Computer Applications
Find the error
for(count = 0, count < 5, count = count + 1)
System.out.println("This is count:" + count);
System.out.println("Done!");
Java Nested for Loops
1 Like
Answer
The errors are as follows:
- The variable count is not declared. It needs to be declared before it can be used.
- The syntax of 'for' loop requires semicolons ( ; ) as separators, and not comma ( , ). The correct code is as follows:
for(int count = 0; count < 5; count = count + 1)
System.out.println("This is count:" + count);
System.out.println("Done!");
Answered By
1 Like
Related Questions
Find the error :
x = 3; y = 4; z = math.power(x*x, y/2);
Predict the output :
class FindFac { public static void main (String args[]) { for(int i = 2; i <= 100; i++) { System.out.print("Factors of" + i + ": "); for(int j = 2; j < i; j++) if((i % j) == 0) System.out.print(j + " "); System.out.println(); } } }
Find the error:
class Test { public static void main (String args[]) { int x = 10; if(x == 10) { int y = 20; System.out.println("x and y: "+ x +" "+ y); x = y * 2; } y = 100; System.out.println("x is"+ x); } }
Give the output of the following program segment and also mention how many times the loop is executed.
int i; for (i = 5 ; i > 10; i++) System.out.println(i); System.out.println(i * 4);