/*
Do While loop Example
This Java Example shows how to use do while loop to iterate in Java program.
*/
public class DoWhileExample {
public static void main(String[] args) {
/*
* Do while loop executes statment until certain condition become false.
* Syntax of do while loop is
*
* do
* <loop body>
* while(<condition>);
*
* where <condition> is a boolean expression.
*
* Please not that the condition is evaluated after executing the loop body.
* So loop will be executed at least once even if the condition is false.
*/
int i =0;
do
{
System.out.println("i is : " + i);
i++;
}while(i < 5);
}
}
/*
Output would be
i is : 0
i is : 1
i is : 2
i is : 3
i is : 4
*/
Bookmark/Search this post with:
Import data
wat if ud like to get the same statement but instead ask the user to key in the data how would the program be??
You'd have to import
You'd have to import scanner, and set i to the scanner.
An easy way
An easy way would be to use InputStreamReader class and wrap it with BufferedReader class. Then parse the inputted value and set the variable with that value.
Post new comment