006-004-002
Do-While Loop: Repeat Password
Easy
Problem Description
Do-while loop: Repeat Password
In this problem, you will create a program that repeatedly prompts for a password using a do-while loop and displays "Correct!" when the entered password matches the correct one.
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!
Examples
Example 1: Wrong once then correct
Input:
secret
wrong
secret
Output:
Enter password: wrong
Incorrect
Enter password: secret
Correct!
Example 2: Correct from start
Input:
pass123
pass123
Output:
Enter password: pass123
Correct!
Example 3: Multiple wrong then correct
Input:
abc
xyz
def
abc
Output:
Enter password: xyz
Incorrect
Enter password: def
Incorrect
Enter password: abc
Correct!
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
dragon qwerty dragon
Expected Output:
Enter password: Incorrect Enter password: Correct!
Normal case
Input:
admin admin
Expected Output:
Enter password: Correct!
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 10 free executions remaining
