Explored while and do while loops
This commit is contained in:
parent
190d61afe6
commit
4969478280
3 changed files with 59 additions and 4 deletions
|
|
@ -5,9 +5,9 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="Made a calculator using Switches">
|
||||
<change afterPath="$PROJECT_DIR$/out/production/java_practice/Calculator.class" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/practice_projects/src/Calculator.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/practice_projects/src/WhileLoops.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/Calculator.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/java_practice/Calculator.class" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -64,6 +64,7 @@
|
|||
"Application.EnhancedSwitches.executor": "Run",
|
||||
"Application.Main.executor": "Run",
|
||||
"Application.TempConverter.executor": "Run",
|
||||
"Application.WhileLoops.executor": "Run",
|
||||
"Application.compountInterest.executor": "Run",
|
||||
"Application.ifStatements.executor": "Run",
|
||||
"Application.madLibs.executor": "Run",
|
||||
|
|
@ -120,7 +121,7 @@
|
|||
<workItem from="1767557093354" duration="14440000" />
|
||||
<workItem from="1767678323979" duration="16130000" />
|
||||
<workItem from="1767837943314" duration="237000" />
|
||||
<workItem from="1767838192168" duration="2611000" />
|
||||
<workItem from="1767838192168" duration="5894000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="updated module output folders">
|
||||
<option name="closed" value="true" />
|
||||
|
|
@ -274,7 +275,15 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1767839480914</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="20" />
|
||||
<task id="LOCAL-00020" summary="Made a calculator using Switches">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767840813715</created>
|
||||
<option name="number" value="00020" />
|
||||
<option name="presentableId" value="LOCAL-00020" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767840813715</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="21" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
|
|
|
|||
BIN
out/production/java_practice/WhileLoops.class
Normal file
BIN
out/production/java_practice/WhileLoops.class
Normal file
Binary file not shown.
46
practice_projects/src/WhileLoops.java
Normal file
46
practice_projects/src/WhileLoops.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class WhileLoops {
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
String name = "";
|
||||
|
||||
// Get users name
|
||||
while(name.isEmpty()){
|
||||
System.out.print("Enter your name: ");
|
||||
name = scanner.nextLine();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get users age
|
||||
int age = 0;
|
||||
|
||||
do{
|
||||
System.out.println("Enter your age: ");
|
||||
System.out.println("(Your age can't be negative)");
|
||||
age = scanner.nextInt();
|
||||
|
||||
}while(age < 0);
|
||||
|
||||
// Greet them
|
||||
System.out.printf("Hello %s. You are %d years old!\n", name, age);
|
||||
|
||||
|
||||
// ask a user to enter a number between 1 - 10;
|
||||
int number = 0;
|
||||
do{
|
||||
System.out.print("Enter a number between 1-10: ");
|
||||
number = scanner.nextInt();
|
||||
|
||||
|
||||
} while(number < 1 || number > 10);
|
||||
|
||||
System.out.printf("Wow %s. You picked %d", name, number);
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue