ICSE Class 10 Computer Applications Question 27 of 30

Solved Sample Paper 3 — Question 27

Back to all questions
27
Question

Question 2(vii)

Find out the error(s) in the following code and underlining correct error(s).

int m = 5; n = 10; 
while(n >= 1)
{
    System.out.print("m");
    n--;
}
Answer

There are two errors in this code:

  1. Variable n is not declared.
  2. Instead of printing variable m, string "m" is printed inside the loop.
int m = 5, n = 10; //correction 1
while(n >= 1)
{
    System.out.print(m); //correction 2
    n--;
}