Answer the following Questions: (DO IT AS EARLY AS POSSIBLE )
Date :17/10/2013
Date :17/10/2013
( OLD CBSE Exam QUESTIONS )
1
|
Find the Output of the following Program
What will be the value of A and B after the execution of the following
code ?
Int A=100, B;
for (B=10;B<=12;B++)
{
A+=B;
}
JoptionPane.ShowMessageDialog(this, ”A:” +A + “ B :” +B “ “);
|
2
|
What will be content of the jTextArea1 after executing the following
code (Assuming that JTextArea1 had no content before executing this code)?
for (int i =2;i<5;i++)
{
jTextArea1. SetText (JTextarea1.getText() + “ “ +
Integer.toString(i*i));
}
|
3
|
What will be content of the jTextArea1 after executing the following
code (Assuming that JTextArea1 had no content before executing this code)?
for (int c =1;c<=4;c++)
{
jTextArea1. SetText (JTextarea1.getText() + “ “ + Integer.toString(c*c));
}
|
4
|
What will be displayed in of jTextField1 after executing the
following code ?
Int N =20;
N=N+1;
If (N<21)
jTextField1.setText(Integer.
toString (N+10));
else
jTextField1.setText(Integer.
toString (N+10));
|
5
|
Rewrite the following code using a Switch statement
if ( code == 1)
Day= “ Monday”;
else if ( code == 2)
Day= “ Tuesday”;
else if ( code == 3)
Day= “ Wednesday”;
else if ( code == 4)
Day= “ Thursday”;
else
Day=” No Match”;
|
6
|
The following code has some errors. Rewrite the correct code
underlining all the correction made
Int p=3; sum=0;
{
sum=p;
P+=3;
}
while(p<=12)
jTextField1(Integer.tostring(sum));
|
7
|
The following code has some errors. Rewrite the correct code
underlining all the correction made
Int total=0,jump=5;
Int I;
for (i=0;i=<5;i++)
{
Jump +=5;
Total+=jump;
}
jTextArea1.ShowText( “ “ +total);
|
8
|
What will be displayed in of jTextField1 after executing the
following code?
int m =16
m=m+1;
If (m < 15)
jTextField1.setText(Integer.
toString (m));
else
jTextField1.setText(Integer.
toString (m+15));
|
9
|
Rewrite the following code using a Switch statement
if ( code == 1)
Month= “ January”;
else if ( code == 2)
Month= “ February”;
else if ( code == 3)
Month= “March”;
else if ( code == 4)
Month= “April”;
else
Month= “No Match”;
|
10
|
The following code has some errors. Rewrite the correct code
underlining all the correction made
Int k=2; sum=0;
{
sum=k;
k+=3;
}
while(k=<20)
jTextField1(Integer.tostring(sum));
|
11
|
The following code has some errors. Rewrite the correct code
underlining all the correction made
Int Sum=0,Step=5;
Int I;
for (i=0;i=<5;i++)
{
Step +=5;
Sum +=Step;
}
jTextArea1.ShowText( “ “ +sum);
|
12
|
What will be the values of variables ‘m’ and ‘n’ after execution of
the following code?
int m,n=0;
for(m=1;m<=4;m++)
{
n+ = m;
n--;
}
|
Note: Read the question properly before finalizing the answer. Ignore case sensitive for finding the output
1
|
Find the Output of the following Program
for( int i==12;i>5;i-2){
jTextArea1.append(String.valueof(i) +”\n”);
}
|
||||||||||
2
|
Find the Output of the following Program
int i,sum;
for( int i=10, sum=5;sum<15;i++)
{sum+ =I;
jTextArea1.append(“ Sum is :”+String.Value of(sum) + “\n”); }
|
||||||||||
3
|
Find the Output of the following Program
int c=0,i=2;
while (i<10){
c=++I –i*2;
}
jTextField1.setText(“c=”+String .Valueof(c)+”i=” +String.Valueof(i));
|
||||||||||
4
|
Find the Output of the following Program
int i, j, a=10,b=8;
for(i=0;i<=a;i++)
jTextField1.setText(String. Valueof(i);
for(j=0;i<=a;j++)
jTextField1.setText(String. Valueof(++j);
b=a;
++a;
b++;
jTextArea1.append(String.Value of(a) + “\n”+ String.Value of(b)+ “\n”);
}
jTextArea1.append(String.Value of(--b));
|
||||||||||
5
|
Find the Output of the following Program
int i, sum=0;
I = 1;
while(i<=10){
sum=sum + i;
i+=3;
}
jTextField1.setText(“c=”+String .Valueof(sum));
|
||||||||||
6
|
How many times will the following loop gets executed
x=5;
y=36;
while (x<=y)
{
x+=6;
}
|
||||||||||
7
|
What will be the content of the jTextArea1 after executing the
following code?
int num=1;
do
{
jTextArea1.setText(Interger.toString(++num)+”\n”);
num=num+1;
}While(num(<=10);
|
||||||||||
8
|
Find the Output of the following Program
int n;
n=1;
while (n<=31)
{
N=2*n;
jTextArea.append(String.valueOf(n)+ “\n”);
}
|
||||||||||
9
|
Find the Output of the following Program
int x, y;
x=5;
y=1;
while(x>0)
{ x=x-1;
y=y*x;
jTextArea1.append(String.valueOf(y) +”\n”);
|
||||||||||
10
|
Find the Output of the following Program
int i =1;
while (i<10){
jTextArea1.append(String.valueOf(i) +”\n”);
i=i*2;
}
|
||||||||||
11
|
Write an appropriate for loop for the situation described below;
A loop is to be repeated 200
times , except the loop is to be terminated if the value of the variables X
become 175
|
||||||||||
12
|
How many times will the following loop gets executed
|
||||||||||
13
|
Find the Output of the following Program
a. for
( int i =10;i>6;i=i-2)
jTextArea.append(String.valueOf(i)
+”\n”);
b. int
i=1;
while (i<5) {
jTextArea1.append(String.valueOf(i));
i=i*2;
}
c. int
total=0, sum=0,i;
for ( int i =0;i<10;i++)
sum+=I;
jTextField1.setText(String.valueOf(total));
d. for
( int j =0 ; j<=10 ;j++)
jTextArea1.append(String.valueOf(++j));
|
Sample
Questions
1
|
Which
element are needed to control a Loop?
|
||||||||||||||||||||||||||||||
2
|
A list namely myList has SelectionMode property set to SINGLE-INTERVAL.
How would you obtain
(i) the
indices of selected value? (ii) the selected value?
|
||||||||||||||||||||||||||||||
3
|
Find the
output:
I. int f=1,i=2;
do
{
f*=i;
} while(++I <5);
System.out.println(f);
|
||||||||||||||||||||||||||||||
II. int j=1,s=0;
while(j<10)
{
System.out.print(j
+ “+”);
S=s+j;
J=j+j%3;
}
|
|||||||||||||||||||||||||||||||
4
|
a.
Rewrite the code using While Loop?
int i,j;
for(i=1;i<=4;i++)
{
for
(j=1;j<=i;j++)
System.out.printl(
“ “+j);
Sytem.out.println();
}
|
||||||||||||||||||||||||||||||
b.
Rewrite the code using While Loop?
int i,j;
for(i=1;i<=4;i++)
{
for
(j=1;j<=i;j++)
System.out.printl(
“ “+j);
Sytem.out.println();
}
|
|||||||||||||||||||||||||||||||
5
|
Write a
program to take input of a variable and show the sum of all even numbers less
than that given number input by the user.
|
||||||||||||||||||||||||||||||
6
|
|||||||||||||||||||||||||||||||
7
|
|
||||||||||||||||||||||||||||||
8
|
What will be the output of the following code
segments:
int a=5, b=10, c=9, d=8;
System.out.println(“” +
((a++)+(++c)-(--b)+(d--));
System.out.println(“” +
((a>b)?(c>d)?(++d):35:(--b)));
|
||||||||||||||||||||||||||||||
9
|
Convert the following code segment using
switch-case construct:
int num = Integer.parseInt(txtNum.getText());
if(num>=2 && num<=5)
txtRes.setText(“Prime”);
else if(num==6 || num==8 || num==10)
txtRes.setText(“Even”);
else
txtRes.setText(“Not Valid”);
|
||||||||||||||||||||||||||||||
10
|
Predict the output of the following java
construct:
int m=5;
int prod=1;
int i=1;
while(i<=5)
{
prod=prod+prod*(m%2);
--m;
++i;
}
System.out.println(“”+prod);
|
||||||||||||||||||||||||||||||
11
|
What is the difference between an ordinary method
and a Constructor?
|
||||||||||||||||||||||||||||||
12
|
What are the actual and formal parameters? Give
example to support your answer.
|
||||||||||||||||||||||||||||||
13
|
Explain the use of Comments in Java with example.
|
||||||||||||||||||||||||||||||
14
|
Write a method in Java that takes a number as
parameter and return sum of its divisors.
|
||||||||||||||||||||||||||||||
15
|
What will be the value of s after executing the following code?
double i,sum=2
for(i=3;i<8;++i)
{ if(i%4= =0)
{ break;
sum=Math.pow(sum,i);
}
else
sum+=i/2;
}
|
||||||||||||||||||||||||||||||
16
|
Haldwani Centre of Computer Mall wants to
computerize its billing process. It offers 3 types of processor in the
Notebook PC. Notebook PC comes with 2 GB RAM but if customer wants 4 GB RAM,
he has to pay an additional Rs. 2000/-.
Company also offering 8% discount due to festive season.
a. Price of processor should be displayed in
priceTF according to processor type selected by customer.
b. NameTF can not accept numeric value. if user
do so, he/she should get an error message.
c. On click of Clear button, all textfield will
be clear and default choice of processor becomes i5 430M.
d. Discount and Net price will be calculated on the click of Calc Price button as per the criteria given above. |