What gets printed when the following program is compiled and run. Select the one correct answer.
1.class
test {
public static void main(
String args[]) {
int i,j,k,l=0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);
}
}
0
1
2
answer is 1.
2.public class test {
public static void main(String args[]) {
int i, j;
int k = 0;
j = 2;
k = j = i = 1;
System.out.println(k);
}
}
The program does not compile as k is being read without being initialized.
The program does not compile because of the statement k = j = i = 1;
The program compiles and runs printing 0.
The program compiles and runs printing 1.
The program compiles and runs printing 2.
answer is it prints 2.