What is the result?

Given the code fragment: What is the result?

Given the code fragment: What is the result?

A.
Compilation fails

B.
10 8 6 4 2 0

C.
10 8 6 4 2

D.
AnArithmeticException is thrown at runtime

E.
The program goes into an infinite loop outputting: 10 8 6 4 2 0. . .



Leave a Reply 1

Your email address will not be published. Required fields are marked *


renko

renko

Answer: B

Code question:
public class Main {

public static void main(String[] args) {

int row = 10;
for ( ; row > 0; ) {
int col = row;
while (col >= 0) {
System.out.print(col + ” “);
col -= 2;
}
row = row / col;
}
}

}
Output:
10 8 6 4 2 0