27 Int x = 99, y = 10;
y = ++x;
System.out.println(“X:”+x+” Y:”+y);
28 double x = 0.055,y = 100.05;
System.out.println((int)(x*y));
29 int x = 10, y=15;
x = x+y;
y = x-y;
x = x-y;
System.out.println(x+ “ *** ”+y);
30 int sum = 20;
if(sum<20)
System.out.print(“Under ”);
else
System.out.println(“Over “);
System.out.println(“the limit”);
31 What will be the output, if n = 1 and if n= 2 in
the following code?
switch(n)
{
case 1:
System.out.println(“One);
break;
case 2:
System.out.println(“ Zero”);
default:
System.out.println(“Wrong input”);
}
32 int s=1,p=0;
for(int j = 1;j<=8;j++)
{
if(j<=4)
s*=j;
else
p+=j;
}
System.out.println(s+” “+p);
33 If array[]={1,9,8,5,2};
i) What is array.length?
ii) What is array[2]?
34 int x[]={1,2,3,4,5}, y ={5,4,3,2,1};
int i,j;
for(i=0,j=x.length;i<x.length;i++,j- -)
System.out.println(x[i] * y[j]);
35 String s = “Please come, let us go to play”;
System.out.println (s.substring(7,11));
System.out.println (s.lastIndexOf(‘o’));
System.out.println (s.toUpperCase());
System.out.println (s.charAt(17));
System.out.println (s.indexOf(9,’o’));
System.out.println (s.substring(0,6) +
s.substring(20,22));
36 Sting k=”WELCOME TOPPERS”
System.out.println(k.toLowerCase());
System.out.println(k.length());
System.out.println(k.indexOf(‘E’));
System.out.println(k.replace(‘O’,’A’));
System.out.println(k.substring(8));
37 String n = “Computer Knowledge.”;
String m = “Computer Application”;
System.out.println
(n.substring(0,8).concat (m.substring(9)));
System.out.println(n.endsWith(“e”);
38 System.out.println(“Four:”+(4+2));
System.out.println(“Four:”+2+2);
39 State the output of the following code
fragment, where int choice =1, x= 0;
y = 0, z=0;
switch(choice++)
{
case 2: x++; y--; z++;
break;
case 3: x+=2; y+=3; z-=3;
default: ++x; ++y; ++z;
}
System.out.println(“X=”+x+”Y =”+y+”Z=”+z);
Questions to practice to find LOGICAL and SYNTAX error in the code
1. public int getData(int num1, int num2)
{
int result = num1 + num2;
System.out.println(“Result is :” +
result);
}
2. class Add
{
public void doAddition(int x, y)
{
System.out.print(x+y);
}
}
3. if(x = 1)
k=100;
else
k = 10;
4. if ( x > y)
System.out. println(“y is greater”);
else
System.out. println(“x is greater”);
5. int i=5, j = 10
if ( (i < j) || (i=10))
System.out.println(“OK”);
System.out.println(“not OK);
6. int x=0;
while(x < 10)
System.out.println(x);
x ++;
7. for ( x = 0; x>= 10; x- -)
System.out.println(x);
8. for (i = 0, i <= 25; i ++)
System.out.println(i);
System.out.println(“the value is “;x);