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 39 40 41 42 43 |
/* 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 */ |
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 scanner, and set i to the scanner.
its time to use the scanner
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.
can you give an example java program using method w/ the use of while loop statement?
is there any more complicate do while loops example…
that has a command of yes/no to terminate the pr0gram…
how to combine do while loop and if else statement?
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”);
break;
}while(name==”john”);
}
}
• There are total 21 stones. • User will start picking the stones. • User cannot pick more than 3 or remaining stones (whichever is less). • After the user picks the stones, computer does its picking. • Computer cannot pick more than 3 or remaining stones (whichever is less). • Repeat the picking (User and Computer) if stones are available. • Whoever is forced to pick up the last stone loses the game. • Your program should ensure that the computer always wins. ( can u tell me how to solve this problem with this method)
4 system. out. println this how to running
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..
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);
}
}
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
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);
}
}
may i know the code for this output pls…
output:
enter no. of loops:5
hello
hello
hello
hello
hello
int i =0;
do{
System.out.println( “Hello”);
i++;
}while( i <5 );
Can someone help me with these?
Need to find the factorial.
Input:3
result:6
3x2x1=6
using the do while statement
int i = 3;
do{
System.out.println(i);
i–;
}while( i * 2) ;
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
Hello! I want to know the program of above output.
1
2
3
4
5
6
7
8
9
19
Boom!
may i know the code for that output?
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!”);
}
}
how to sum of a integer value
like that
int i=1534;
let 1+5+3+4 how…..
may i know the code for this output please….using while looping.
11111
11111
11111
11111
11111
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..
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..
can you give me the source code of for,while,do,infinite loop??
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.
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.
can u any one tel this code my question is sum of 3 numbers the sum is even numkber print is even number
Help!!
I need to create a program where the user inputs height – program asks for if the user wants to input more heights? if yes you program loops back to the start – if not, drops out and gives the average of heights and asks the user if they want to continue or terminate the program???
may i know the code of this output using while loop
1
22
333
4444
55555
4444
333
22
1
….5
…4.
..3..
.2…
1….
how to do this using while code only. ty
do { Happy weekend; } While (y <5); alert(“Good job!”); Var y=5 ;
pls I want to get answer to this question very urgent
do { Happy weekend; } While (y <5); alert(“Good job!”); Var y=5 ;