-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDoWhile.java
32 lines (26 loc) · 1.02 KB
/
DoWhile.java
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
import java.util.*;
public class DoWhile
{
public static void main (String[] args) {
/*REMEMBER FOR LOOPING ICU METHOD
-I:Initialization
-C: Condition to Check true:false
-U: Update else it will be an infinite loop and you do not want that
*/
String password = "passpass";
Scanner scanner = new Scanner(System.in);
String guessed;
do
{
System.out.println("This device is prompting you to enter the password to gain access");
guessed = scanner.nextLine();
}
//Notice how guessed is declared then defined because if we didn't do that
//error will be raised "guessed is not defined" as soon as we reach the while loop execution
while(!guessed.equals(password));
System.out.println("Congratulations you're not a mong!");
//When finishin with a scanner REMEMBER
scanner.close();
//This frees memory and prevents a memory leak
}
}