006-004-002
Do-While Loop: Repeat Password
Easy
Problem Description
Do-While Loop: Repeat Password
Learning Objective: Learn processing executed at least once with do-while loop
Create program that repeatedly requests input until correct password entered. Use do-while loop to accept input at least once.
Input
Line 1: Correct password (string)
Line 2 onwards: Entered passwords (string, multiple lines)
Output
Enter password: [input1]
Incorrect
Enter password: [input2]
Correct!
```java
## Examples
### Example 1: Wrong once then correct
Input:
```java
secret
wrong
secret
```java
Output:
```java
Enter password: wrong
Incorrect
Enter password: secret
Correct!
```java
### Example 2: Correct from start
Input:
```java
pass123
pass123
```java
Output:
```java
Enter password: pass123
Correct!
```java
### Example 3: Multiple wrong then correct
Input:
```java
abc
xyz
def
abc
```java
Output:
```java
Enter password: xyz
Incorrect
Enter password: def
Incorrect
Enter password: abc
Correct!
Test Cases
※ Output examples follow programming industry standards
Input:
secret wrong secret
Expected Output:
Enter password: Incorrect Enter password: Correct!
Input:
pass123 pass123
Expected Output:
Enter password: Correct!
Input:
abc xyz def abc
Expected Output:
Enter password: Incorrect Enter password: Incorrect Enter password: Correct!
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 9 free executions remaining
