The document contains 14 questions asking to write Java code to solve various programming problems. The problems include counting vowels in a string, checking if a string is a palindrome, selecting a car model from a dropdown and displaying the corresponding company, reversing digits of a number, calculating fare based on distance traveled, finding the largest of three numbers, calculating total amount based on payment method, calculating call amounts and discounts, converting a string to uppercase and finding its length, calculating employee salary based on basic pay, and other problems involving factorials, digit sums, Armstrong numbers, prime numbers, and palindrome of a string.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
132 views
Practical Questions Netbeans
The document contains 14 questions asking to write Java code to solve various programming problems. The problems include counting vowels in a string, checking if a string is a palindrome, selecting a car model from a dropdown and displaying the corresponding company, reversing digits of a number, calculating fare based on distance traveled, finding the largest of three numbers, calculating total amount based on payment method, calculating call amounts and discounts, converting a string to uppercase and finding its length, calculating employee salary based on basic pay, and other problems involving factorials, digit sums, Armstrong numbers, prime numbers, and palindrome of a string.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16
Q1.
Write a program to count number of vowels in a string
String k = jTextField1.getText(); String j=k.toLowerCase(); int l = 0; int m =j.length(); for(int i=0; i<m;i++) { String p = j.substring(i,i+1); if(p.equals("a")|| p.equals("e") || p.equals("i") || p.equals("o") || p.equals("u")) l++; } jTextField2.setText(Integer.toString(l));
Q3. Write code to find if a string is palindrome
String a = jTextField1.getText(); int b = a.length(); String c = ""; while (b>=1) { String k = a.substring(b-1,b); c=c+k; b--; } if (a.equals(c)) jTextField2.setText("Palindrome"); else jTextField2.setText("Not Palindrome");
Q4. Write code to select a car model from jcombobox1 and display the name of the company in the text field.
Q5. Write an application to reverse digits of a given number
int a = Integer.parseInt(jTextField1.getText()); int dig; int rev=0; while (a>0) { dig = a%10; rev = rev*10+dig; a = a/10; } jTextField2.setText(Integer.toString(rev)); }
Q6. Write an application to calculate fare for transport system If km 0-50, fare Rs 10 If km 50-100, fare Rs 25 If km >100, fare Rs35
int busno; String startpoint; String dest; float km; int fare; busno = Integer.parseInt(jTextField1.getText()); startpoint = jTextField2.getText(); dest = jTextField3.getText(); km = Float.parseFloat(jTextField4.getText()); if (km<50) fare = 10; else if (km<100) fare = 25; else if (km>100) fare = 35; jTextField5.setText(Integer.toString(fare));
Q7. Write function that accepts 3 integers as parameters and finds the largest of them
int a = Integer.parseInt(jTextField1.getText()); int b = Integer.parseInt(jTextField2.getText()); int c = Integer.parseInt(jTextField3.getText()); { int max=0; if (a>b&&a>c) max=a; else if (b>a&&b>c) max=b; else if (c>a&&c>b) max=c; jTextField4.setText(Integer.toString(max)); }
Q8). Write down an application which accepts cost and quantity of all items from the user and calculates total amount By cash, tax =0 By cheque, tax = 1.5 By credit card, tax = 2.5
float i1 = Float.parseFloat(jTextField1.getText()); float i2 = Float.parseFloat(jTextField2.getText()); float i3 = Float.parseFloat(jTextField3.getText()); int q1 = Integer.parseInt(jTextField4.getText()); int q2 = Integer.parseInt(jTextField5.getText()); int q3 = Integer.parseInt(jTextField6.getText()); float a = i1*q1; float b = i2*q2; float c = i3*q3; float amt = a+b+c; double total=0; if (jRadioButton1.isSelected()) total = amt; else if (jRadioButton2.isSelected()) total = amt + 2.5/100*amt; else if (jRadioButton3.isSelected()) total = amt + 1.5/100*amt; jTextField7.setText(Float.toString(amt)); jTextField8.setText(Double.toString(total)); }
Q10. Write an application which accepts local and std calls and calculates amount . General customer, discount = o Student , discount = .2 Handicap, discount = 2.5 Bonafide customer, discount = .5
double std; double local; double amt; std = s*1.25; local = l*.50; amt = std +local; double disc=0; double total=0; if (jRadioButton1.isSelected()) disc = 0; else if (jRadioButton2.isSelected()) disc = .2/100*amt; else if (jRadioButton3.isSelected()) disc = 2.5/100*amt; total = amt - disc; if (jCheckBox1.isSelected()) total = total-.5/100*total; jTextField5.setText(Double.toString(amt)); jTextField6.setText(Double.toString(total)); }
Q12. Write code to convert the a string to uppercase and find its length
String x =jTextField1.getText(); int b = x.length(); jTextField3.setText(Integer.toString(b)); String k = x.toUpperCase(); jTextField2.setText(k);
Q14. Calculate salary of an employee accept empno, ename, basic calculate net as gross pf Where gross = basic+hra+da Hra = 20% of basic Da = 15% of basic Pf = 12% of basic
int empno; String ename; float basic; float net; empno = Integer.parseInt(jTextField1.getText()); ename = jTextField2.getText(); basic = Float.parseFloat(jTextField3.getText()); float hra; float da; float pf; float gross; hra = basic*20/100; da = basic*15/100; gross = basic + hra + da; pf = basic*12/100; net = gross - pf; jTextField4.setText(Float.toString(net));
Q) calculate Factorial
Int num= Integer.parseInt(jTextField1.getText()); Int fact=1, a; For(a=1;a<=num;a++) { Fact=fact*a; } System.out.println(fact);
2) calculate Sum of digits:
Int num= Integer.parseInt(jTextField1.getText()); Int digit, sum=0; While(num>0) { Digit=num%10; Sum=sum+digit; Num=num/10; } System.out.println(sum);
4) check whether a given number is a Palindrome or not
Int num= Integer.parseInt(jTextField1.getText()); Int digit, rev=0; Int y=num; While(num>0) { Digit=num%10; Rev=rev*10+digit; Num=num/10; }
If(y==rev) System.out.println( It is a palindrome); Else System.out.println( It is not a palindrome);
5) check whether a number is an Armstrong number or not
Int num= Integer.parseInt(jTextField1.getText()); Int digit, sum=0; Int y=num; While(num>0) { Digit=num%10; Sum=sum+(digit*digit*digit); Num=num/10; }
If(y==sum) System.out.println( It is an Armstrong number); Else System.out.println( It is not a Armstrong number);
6) Prime number
Int num= Integer.parseInt(jTextField1.getText()); Int a=1; For(int i=2;i<n;i++) { If(num%i==0) { a=0; Break; }}
If(a==1) System.out.println( It is a prime number); Else System.out.println( It is not a prime number);
7) Palindrome of a string
String a = jTextField1.getText(); int b = a.length(); String c = ""; while (b>=1) { String k = a.substring(b-1,b); c=c.concat(k); b--; } if (a.equals(c)) jTextField2.setText("Palindrome"); else jTextField2.setText("Not Palindrome");
Where can buy Industrial Vision Systems with Raspberry Pi Build and Design Vision products Using Python and OpenCV 1st Edition Mohaideen A ebook with cheap price
Where can buy Industrial Vision Systems with Raspberry Pi Build and Design Vision products Using Python and OpenCV 1st Edition Mohaideen A ebook with cheap price