2 1
2 1
until 0 *
Requirements:
Hardware : CPU, Monitor, Keyboard, Mouse, UPS, Printer.
Software : Windows 7 OS , JDK 1.8, Notepad
Theory:
while loop-: A type of loop which execute the statement starting from
initialization and continue up to the the condition satisfied.
Syntax of while loop
while (condition)
{
Statements;
}
Procedure:
1. Start button was clicked.
2. Then All programs >Notepad was opened.
3. write a java program
4. then go to file menu
5. then click on save as.
6. choose desktop and select save as type: “all files”.
7. after select save as type then write file name with extension name
8. Then “save” button was clicked.
9. Now again go to command prompt and choose proper directory.
10. first compile java program with java compiler.
11. after the compilation successfully then it generate java class
file .
12. then run java program
Programming
import java.util.*;
public class Loopuse
{
public static void main(String[] args)
{
int i;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
i = sc.nextInt();
while(i!=0)
{
System.out.println("You have enterd-:"+i);
i = sc.nextInt();
}
System.out.println("You have enterd 0");
}
}
Select directory:- cd desktop
Compile:- javac Loopuse.java
Run:- java Loopuse
Out put
C:\Users\UNIITECH>cd desktop
C:\Users\UNIITECH\Desktop>javac Loopuse.java
C:\Users\UNIITECH\Desktop>java Loopuse
Output
Enter a number
45
You have enterd-:45
62
You have enterd-:62
0
You have enterd 0
Conclusion:
In the above experiment, I entered different numbers , which are displayed, and
finally entered 0 to stop execution.