java-.docx

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.

Q2.1

A.

B.

C.

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.