Can someone explain the following questions from a mock java exam.
1.To what value must result be set for the loop to execute 2 times:
int num = 23;
int result = ?;
while((num>1)&& (result<32)) {
num = num/2;
result= result + 1
}
The answer that is on the answer sheet is 29, can someone explain
how?
2.The following code produces which sequence of numbers?
boolean t;
int a = 0;
int b = 1;
int c = 1;
for(int n = 0; a < 25; n++) {
t = false;
for (int j = a ; j < a + 4; j++) {
if (a%2==0) t = true;
if (t) system.out.println(j);
}
c = a;
a = b;
b = c+b;
}
can some explain how they got the sequence of numbers : 0,1,2,3,2,3,4,5,8,9,10,11
?
3.In the following problem what is printed?
int c = 0;
int d = 23,
do {
c+=3;
d-=1;
}while(c<10 && d!=20);
system.out.println(c+d);
The answer on the sheet is 29, but I get 25?, can someone explain
how they
get 29?
4.Nothing to do with java but this is part of the mock paper.
For the Backus-Naur Form (BNF) grammar which of the following is
an INVALID
string?