Do While loop Example
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
/*
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
39.
40.
41.
42.
43.
Like
i is : 1
i is : 2
i is : 3
i is : 4
*/
14
Tweet
36
Advertisement:
Receive Latest Java examples in your email:
Subscribe
Related Java Examples
While Loop Example
Simple For loop Example
Do While Loop
While Loop
For Loop
Infinite For loop Example
Continue Statement
Java break statement example
25 Comments
javaex
Recommend 8
Share
Login
Sort by Best
Join the discussion
Sahar Css
4 years ago
i want get answer this question plssssss
write a program that inputs a temperatures in C (celsius ) from the keyboard
then prints out the corresponding temperature in fahrenheit
F=C.9/5+32
7
Reply
Amith Anjanappa > Sahar Css
2 years ago
i guess this might be the answer
import java.io.*;
public class TempConv
{
public static void main(String args[])throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String str=buf.readLine();
double temp=Integer.parseInt(str);
double Farhn=temp*9/5+32;
System.out.println("Temperature in Fahrenheit is: "+Farhn);
see more
Reply
nej_jen
4 years ago
Output:
i and j: 0 10
i and j: 1 9
i and j: 2 8
i and j: 3 7
i and j: 4 6
May i know the complete code for this output??plssssss..
6
Reply
Dilip Raghu > nej_jen
4 years ago
class code
{
public static void main(String[] args)
{
int i=0,j=10;
do{
System.out.println("The value of i and j :"+i+ "\t" +j );
i++;
j--;
}while(i<5&&j>5);
}
}
12
Reply
Jerry Castillo
4 years ago
may i know the code for this output pls...
output:
enter no. of loops:5
hello
hello
hello
hello
hello
12
Reply
Mahi > Jerry Castillo
10 months ago
int i =0;
do{
System.out.println( "Hello");
i++;
}while( i <5 );
0
Reply
Anonymous
6 years ago
is there any more complicate do while loops example...
that has a command of yes/no to terminate the pr0gram...
4
Reply
Axel Driege
a year ago
Can i plz have the code for this output i can't find it.
output;
enter a word:
example
example
exampl
examp
exam
exa
ex
e
ex
exa
exam
examp
exampl
example
see more
Reply
Anonymous
6 years ago
how to combine do while loop and if else statement?
1
Reply
Mahi > Anonymous
10 months ago
public class DoWhile {
public static void main(String[] args) {
String name = "john";
String pswd = "2999";
do{
System.out.println("Enter the password :" +pswd);
if(pswd=="2999"){
System.out.println( "Enter the amount");
System.out.println("draw the money");
System.out.println("withdrawl money");
System.out.println("Reciept");
}else
System.out.println("Wrong pin number");
System.out.println("Wrong pin number");
break;
}while(name=="john");
}
}
0
Reply
jenelyn olila
7 months ago
pls help me,this is my final exam in java and its hard for me to do this,,, i
hope somebody could answer my question...how to make a 3 programs with
password..note:the password is included in the code not in the dialog
box.tnx a lot... i want to know what is the code of this...tnx a lot.
0
Reply
refiloe
8 months ago
please help me with the program.
The task makes use of the shortcut if statement to count the number of
distinctions
1.1 write a method to count the number of fails using the shortcut if
statements. call the method in the test class.
1.2 change the shortcut if statement to the normal if statements.
0
Reply
Elman Manalo
8 months ago
can you give me the source code of for,while,do,infinite loop??
0
Reply
Cheii Chu
9 months ago
do you know how to get this ? using do and while loop in java?
Make a program that will ask user to enter 10
numbers. Display only all the even inputs by the user. Use modulo operation
in
this problem. The program must be able to repeat the process if he/she
wants to..
0
Reply
Cheii Chu
9 months ago
Make a program that will ask user to enter 10
numbers. Display only all the even inputs by the user. Use modulo operation
in
this problem. The program must be able to repeat the process if he/she
wants to.. paano po to ? yung "must be repeat"? gamit ang do while ? ang
alam ko lan g po kasi ay "goto" .. paki sagot naman po salamat..
0
Reply
Patrick Miguel G. Beria
9 months ago
may i know the code for this output please....using while looping.
11111
11111
11111
11111
11111
11111
0
Reply
Victoria aguas
a year ago
1
2
3
4
5
6
7
8
9
19
Boom!
may i know the code for that output?
0
Reply
Mahi > Victoria aguas
10 months ago
public class DoWhile {
public static void main(String[] args) {
int i = 1;
int j = 19;
do{
System.out.println(i);
i++;
}while(i<10);
System.out.println(j);
System.out.println("Boom!");
}
}
0
Reply
maria
2 years ago
Can someone help me with these?
Need to find the factorial.
Input:3
result:6
3x2x1=6
using the do while statement
0
Reply
Mahi > maria
10 months ago
int i = 3;
do{
System.out.println(i);
i--;
}while( i * 2) ;
}while( i * 2) ;
0
Reply
Load more comments
Subscribe
Add Disqus to your site Add Disqus Add
Privacy