ICSE Class 10 Computer Applications Question 56 of 76

Revising Basic Java Concepts — Question 60

Back to all questions
60
Question

Question 37

Find the error

for(count = 0,  count < 5,  count = count + 1)	
System.out.println("This is  count:" + count);	
    System.out.println("Done!");	
Answer

The errors are as follows:

  1. The variable count is not declared. It needs to be declared before it can be used.
  2. 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!");