Posts

Java Exercises for you

JAVA Exercises for you  1 1.          What would be output of the following code segment written in java. public static void main(String [] args) {  int a=10, b= 9;     boolean x;     x = a++ == ++b;     System.out.print("x = "+x); }    2   2.       Find the output of the following code snippet written in java public static void main(String []args) {     int x=10, y=5;     System.out.println(x++);     System.out.println(++y);     System.out.println((x++ + ++y));     System.out.println((++x - y++));     System.out.println((x++) + (++y));     System.out.println((++x)-(y++));     System.out.println((x++) + (++x));     System.out.println("x = "+ X +" y="+ y); } 3   3.      ...

Some Important Questions with Answers

Some Important Questions with Answers 1. Which window is used to designed the form. Ans: Design window 2. Which window contains the Swing Controls components. Ans: Palette window 3. What is the most suitable component to accept multiline text. Ans : Text Area 4. What will be the output of the following command? Learning.concat("Java") Ans : Error 5. What will be the output of the following command? "Learning".concat("Java") Ans: LearningJava 6. Name the different list type controls offered by Java Swing. Ans: ( i) jListBox (ii) jComboBox 7. Name any two commonly used method of ListBox. Ans: getSelectedIndex() and getSelectedValue() 8. Write code to add an element (“New Course”) to a list (SubList) at the beginning of the list. Ans : SubList.add(0,”New Course”); 9. Describe the three common controls. Also give some of their properties. Ans: (i) jButton text,icon (ii) jLabel text,border (i...

Short Answers Type Questions:

Short Answers Type Questions: 1.Write the java statement that assigns 1 to x if y is greater than 0 Ans:    if (y > 0) x = 1; 2. Suppose that score is a variable of type double. Write the java statement that increases the score by 5 marks if score is between 80 and 90 Ans : if (score >= 80 && score <=90) score += 5; 3. Rewrite in Java the following statement without using the NOT (!) operator: item = !( (i<10) | | (v>=50) ) Ans : item = i >= 10 && i < 50 4. Write a java statement that prints true if x is an odd number and positive Ans:   if (x % 2 != 0 && x > 0) System.out.println(true); or System.out.println(x%2 !=0 && x>0); // This prints false otherwise 5. Write a java statement that prints true if both x and y are positive numbers Ans :  if (x > 0 && y > 0) System.out.println(true); or System.out.println(x > 0 && y > 0); // This prints ...

Design Solution

Image
Q1  Garments has developed a GUI application for their company as shown below : The company accepts payments in 3 modes- cheque , cash and credit cards. The discount given as per mode of payment is as follows. Mode of Payment   Discount Cash 8% Cheque  7% Credit Card   Nil If the Bill Amount is more than 15000 then the customer gets an additional discount of 10% on Bill Amount  (1) Make Discount and Net amount uneditable. (2) Write codes for calculate Discount and calculate Net Amount Buttons (3) Write code to exit program when STOP button is clicked. Solution: //Code for calculate button  txtDiscount.setEditable(false);  txtNetAmt.setEditable(false);  String name= txtname.getText(); double bm=Double.parseDouble(txtbillamt.getText();); double disc=0.0, netAmt=0.0; String s= cmbMode.getSe...