Problem : Display "Hello Java" five times on the console with help of do-while statements
Program:Step 1 - CodingCreate a text file HelloDoWhile.java and copy below contents./** * A program that prints 'Hello Java' string with help of DoWhile loop statements. */ public class HelloDoWhile { public static void main(String[] args) { int i = 0; do { System.out.println( i+ " Hello Java "); i++; } while (i < 5); } } Step 2 - Deployment
Step 3 - Testing
OutputIt will print Hello five times. 0 Hello Java 1 Hello Java 2 Hello Java 3 Hello Java 4 Hello Java FAQWhat is do-while loop?The do-while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:do { statement(s) } while (expression); The difference between do-while and while is
that do-while evaluates its expression at the bottom of the loop
instead of the top.
Therefore, the statements within the do block are always executed
at least once.<<Previous | Next>> |