Professional Documents
Culture Documents
3. What is the main difference between a while loop and a do while loop?
Ans. While loop is entry control loop and do…while loop is exit control loop. While loop works only if the
given condition is true where as do…while loop works minimum works for one time and then check for
the condition, it works further if given condition is true.
In this example else statement belongs to which if statement? It can match with both if statement. To
avoid this problem we use { } braces.
if ( num > 0 )
{
if ( num < 10 )
System.out.println( "Number in between 0 and 10" ) ;
}
else
System.out.println( "Number is out of Range" ) ;
8. Which expression is optional in for loop? When empty loops are useful?
Ans. All three options of for loop are optional. We use empty loops when we want delay in the program.
9. Name the controls that you will use to enter your Phone number of a student in a form.
Ans. Text Field
10. Name the controls that you will use to enter your Stream in a form.
Ans. Radio Button
11. Name the controls that you will use to get student email address in a form.
Ans. Text Field.
Try it yourself
1. How many times will the following loop get executed?
x = 5;
y = 36;
while ( x <= y)
{
x+=6;
}
2. What will be the content of the jTextArea1 after executing the following code?
int Num = 1;
do
{
jTextArea1.setText(Integer.toString(++Num) + "\n");
Num = Num + 1;
}while(Num<=10)
3. What are relational operators? Explain with the help of suitable examples.
4. What will be the content of jTextField1 after executing the following code:
int Num = 6;
Num = Num + 1;
if ( Num > 5)
jTextField1.setText(Integer.toString(Num));
else
jTextField1.setText(Integer.toString(Num+5));
5. What will be the corresponding outputs of the following code segment if the possible inputs in the
jTextField1 are:
(i) 10 (ii) 20 (iii) 30 (iv) 40 (v) 50
String str = jTextField1.getText();
Number = Integer.parseInt(str);
Switch (Number)
{
case 10:jTextField1.setText("Ten Thousand");break;
case 20:jTextField1.setText ("Twenty Thousand");
case 30:jTextField1.setText ("Thirty Thousand"); break;
case 40:jTextField1.setText ("Forty Thousand");
default:jTextField1.setText ("Not enough!!!");
}
6. Find the output of the following code:
int First = 7;
int Second = 73;
First++;
if (First+Second > 90)
jlabel1.setText("value is 90 ");
else
jlabel1.setText("value is not 90 ");
int Number1 = 7,Number2=8;
int Second = 73;
if (Number1>0 || Number2>5)
if (Number1>7)
jTextField1.setText("Code Worked");
else
jTextField1.setText("Code MightWork");
else
jTextField1.setText("Code will not Work");