Computer Science, asked by ms25205155, 9 months ago

Please read the question carefully and select the correct answer
What will be the output of the following program? class WhileExample { public static
void main(String s[]) {int n = 5; while( n > 0) {n--; System.out.println("n = " + n );}}​

Answers

Answered by prasadkolhatkar17
0

Answer:

Compilation error

Explanation:

First of all this code contains error, in line "public static void main" here M should capital in "Main" and also "String s[]" should be "String[] s" so the correct code is

public static void Main(String[] s)

   {

       int n = 5;

 while( n > 0)

 {

  n--;

  Console.WriteLine("n = " + n );

 }

   }

And then its output is

n = 4

n = 3

n = 2

n = 1

n = 0

Answered by anindyaadhikari13
1

Answer:-

Given code,

class WhileExample

{

public static void main(String s[])

{

int n = 5;

while( n > 0)

{

n--;

System.out.println("n = " + n );

}

}

}

There is no error in this code.

Output will be,

n=4

n=3

n=2

n=1

n=0

Similar questions