Q:

Java program to implement infinite loop using while loop

belongs to collection: Java Basic Programs

0

Java program to implement infinite loop using while loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to implement an infinite loop using the while loop is given below. The given program is compiled and executed successfully.

// Java program to implement infinite loop 
// using while loop

public class Main {
  public static void main(String[] args) {
    while (true) {
      System.out.println("Hello");
    }
  }
}

Output:

Hello
Hello
Hello
Hello
Hello
.
.
Infinite time

Explanation:

In the above program, we created a public class Main. It contains a static method main().

The main() method is an entry point for the program. Here, we used Boolean value true in the while loop for condition. That's why the while loop will never terminate and printed "Hello" message infinite times.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to implement infinite loop using do-w... >>
<< Java program to SET and CLEAR bits of the given nu...