Computer Science, asked by Amaresh16, 1 year ago

Write an java application that keeps displaying in the command window the multiples of the integer 2—namely, 2, 4, 8, 16, 32, 64, etc. Your loop should not terminate (i.e., create an infinite loop). What happens when you run this program?

Answers

Answered by alinakincsem
0

Java application that keeps displaying in the command window the multiples of the integer 2

public class printer

{

    public static void main(String args[])

{

               int i = 0;

 System.out.println("\nMultiple of 2: ");  

  while(1)                                               //an infinite loop

                            {

          if (i%2==0)

                 {     System.out.print(i +", ");     }

                                 i++;                  //incrementing variable

               }  

     

}

}

The loop will began infinite run, java become overflow so the program will fail and it will crash also known as memory overloading.

   



Similar questions