Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

loops

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
Could any of you help me in easiest way of cracking loops.
I am very confused.
I post some of the example questions below:


Thanks,
Kishore
 
kishore kovil
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
I am sorry.
I found that some of the content is misplaced by images.
I resend the code.

Question 16
class JMM110 {
public static void main (String[] args) {
int j = 0;
do for (int i = 0; i++ < 2
System.out.print(i);
while (j++ < 2);
}}

What is the result of attempting to compile and run the program?

a. Prints: 0001
b. Prints: 012
c. Prints: 012012
d. Prints: 012345
e. Prints: 001122
f. Prints: 1112
g. Prints: 111222
h. Prints: 121212
i. Run-time error
j. Compile-time error
k. None of the above

--------------------------------------------------------------------------------

Question 17
class JMM111 {
public static void main (String[] args) {
int j = 0;
for (int i = 0; i < 2; i++) do
System.out.print(i);
while (j++ < 2);
}}

What is the result of attempting to compile and run the program?

a. Prints: 0001
b. Prints: 012
c. Prints: 012012
d. Prints: 012345
e. Prints: 001122
f. Prints: 1112
g. Prints: 111222
h. Prints: 121212
i. Run-time error
j. Compile-time error
k. None of the above

--------------------------------------------------------------------------------

Question 18
class JMM112 {
public static void main (String[] args) {
int j = 0;
for (int i = 0; i++ < 2 do
System.out.print(i);
while (j++ < 2);
}}

What is the result of attempting to compile and run the program?

a. Prints: 0001
b. Prints: 012
c. Prints: 012012
d. Prints: 012345
e. Prints: 001122
f. Prints: 1112
g. Prints: 111222
h. Prints: 121212
i. Run-time error
j. Compile-time error
k. None of the above

--------------------------------------------------------------------------------

Question 19
class JMM113 {
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do while (i++ < 3)
System.out.print(k++);
while (j++ < 3);
}}

What is the result of attempting to compile and run the program?

a. Prints: 0001
b. Prints: 012
c. Prints: 012012
d. Prints: 012345
e. Prints: 001122
f. Prints: 1112
g. Prints: 111222
h. Prints: 121212
i. Run-time error
j. Compile-time error
k. None of the above

--------------------------------------------------------------------------------

Question 20
class JMM114 {
public static void main (String[] args) {
int i = 0, j = 0;
while (i++ < 3) do
System.out.print(j);
while (j++ < 3);
}}

What is the result of attempting to compile and run the program?

a. Prints: 0001
b. Prints: 001122
c. Prints: 012012
d. Prints: 012345
e. Prints: 1112
f. Prints: 111222
g. Prints: 121212
h. Run-time error
i. Compile-time error
j. None of the above

--------------------------------------------------------------------------------

Question 21
class JMM115 {
static int m1(String s, int i) {
System.out.print(s + i);
return i;
}
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do while (m1("i", ++i) < 2)
System.out.print("k" + ++k);
while (m1("j", ++j) < 2);
}}

What is the result of attempting to compile and run the program?

a. Prints: i1k1i2k2j1i3j2
b. Prints: i1k1i2k2j1i1k1i2k2j2
c. Prints: i1k1i2j1i3j2
d. Run-time error
e. Compile-time error
f. None of the above

--------------------------------------------------------------------------------

Question 22
class JMM116 {
static int m1(String s, int i) {
System.out.print(s + i);
return i;
}
public static void main (String[] args) {
int j = 0;
for (int i = m1("A",0); m1("B",i) < 2; m1("C",++i)) {
m1("J",++j);
}
}}

What is the result of attempting to compile and run the program?

a. Prints: A0B0C1J1B1C2J2B2
b. Prints: A0B0J1C1B1J2C2B2
c. Prints: A0B0J1C1A1B1J2C2A2B2
d. Run-time error
e. Compile-time error
f. None of the above

--------------------------------------------------------------------------------

Question 23
class JMM117 {
public static void main (String[] args) {
int i = 0, j = 9;
do {
i++;
if (j-- < i++) {break;}
} while (i < 5);
System.out.print(i + "," + j);
}}

What is the result of attempting to compile and run the program?

a. Prints: 5,4
b. Prints: 6,3
c. Prints: 6,6
d. Prints: 7,2
e. Run-time error
f. Compile-time error
g. None of the above

--------------------------------------------------------------------------------

Question 24
class JMM118 {
public static void main (String[] args) {
int i = 0, j = 9;
while (i++ <= j--) {i++; if (j < 5) break;}
System.out.print(i + "," + j);
}}

What is the result of attempting to compile and run the program?

a. Prints: 4,7
b. Prints: 6,6
c. Prints: 7,2
d. Prints: 8,5
e. Prints: 9,4
f. Run-time error
g. Compile-time error
h. None of the above

--------------------------------------------------------------------------------

Question 25
class JMM119 {
public static void main (String[] args) {
int i = 0, j = 9;
do {
if (j < 4) {break;} else if (j-- < 7) {continue;}
i++;
} while (i++ < 7);
System.out.print(i + "," + j);
}}

What is the result of attempting to compile and run the program?

a. Prints: 4,7
b. Prints: 6,6
c. Prints: 6,5
d. Prints: 6,4
e. Prints: 7,5
f. Prints: 8,4
g. Run-time error
h. Compile-time error
i. None of the above

--------------------------------------------------------------------------------

Question 26
class JMM120 {
public static void main (String args[]) {
int i = 0, j = 0, k = 0;
label1:
for (; { i++;
label2:
do {
k = i + j;
switch (k) {
case 0: continue label2;
case 1: continue label1;
case 2: break;
case 3: break label2;
case 4: break label1;
default: break label1;
}
} while (++j<5);
}
System.out.println(i + "," + j);
}}

What is the result of attempting to compile and run the program?

a. Prints: 2,1
b. Prints: 2,2
c. Prints: 3,1
d. Prints: 3,2
e. Prints: 3,3
f. Run-time error
g. Compile-time error
h. None of the above

--------------------------------------------------------------------------------

Question 27
class JMM121 {
public static void main (String args[]) {
int h = 0, i = 0, j = 0, k = 0;
label1:
for (; { h++;
label2:
do { i++; k = h + i + j;
switch (k) {
default: break label1;
case 1: continue label1;
case 2: break;
case 3: break label2;
case 4: continue label2;
case 5: continue label1;
}
} while (++j < 5);
}
System.out.println(h + "," + i + "," + j);
}}

What is the result of attempting to compile and run the program?

a. Prints: 1,2,3
b. Prints: 1,3,2
c. Prints: 2,2,2
d. Prints: 2,4,1
e. Prints: 2,4,2
f. Run-time error
g. Compile-time error
h. None of the above
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Let's discuss this in this duplicate thread.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic