Q1. which of the following is syntactically incorrect? and Why?
int x = 5, y = x; String m1 = "ABc", m2 = m1; String m3 = new String("AbC");
a. if( x.equals(y) )
b. if( m1=m2)
c. if( m2==m3 )
d. if ( x==y )
e. if( m1=null )
f. if( m1.equals(m3) )
g. If( m1.equals(m2)
Q2. What is the output of following questions.
A.int x 5, y 0, z -2;
if(x<0 SS (y<2 II z>2) )
System. out .println("A");
else if(x>0 (y<2 II z>2))
System. out sprintln("8"):
else if(x>0 && (y<2 && z>2))
System. out .println("C");
System.out.println("D");
B.
int x = -1, y = 3, z = -2;
if(x<0 && (y<2 II z>2) )
System. out .print("A");
else if(x>0 && (y<2 II z>2))
System. out .print("8");
else if(x>0 it (y<2 && z>2))
System. out. print("C");
System.out.println("D");
C.
int i;
int sum=o; for(i=0; i<5 ;i++)
{
if(i>1)
sum=sum+i;
}
System.out.println("Sum is " + sum); System.out.println("last value of i is + i);
Q2.1
if(x>0)
{
if (yif(z==y)
System. out.println("A");
}
}
else
System.out.println("B");
Q2.2. Given the code:
what is the output in each of the following cases? a. x=6, y=0, z=0
b. x=2, y=-1, z=-2
c. x=-1, y=-2, z=-2
d. x=0, y=-2, z=-2
e. x=3, y=-1, z=-1
Q3.Convert the following for loop into a while loop.
int sum = 0;
for (int i = 10; i > 10; i--) sum = sum + I;
Q4. Write a program called CheckPass which read the mark from user in double and prints "PASS" if the mark is more than or equal to 60; or prints "FAIL" otherwise.