-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sign_up
55 lines (44 loc) · 1.86 KB
/
Sign_up
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package Learn_and_Build;
import java.util.Scanner;
public class Sign_Up {
public static void main(String[] args) {
String[] usernames = new String[10]; // array to store usernames
String[] passwords = new String[10]; // array to store passwords
int count = 0; // variable to keep track of the number of users signed up
Scanner input = new Scanner(System.in);
// loop to allow multiple sign ups
while (true) {
System.out.println("Enter a username:");
String username = input.nextLine();
// check if the username already exists
boolean usernameExists = false;
for (int i = 0; i < count; i++) {
if (usernames[i].equals(username)) {
System.out.println("That username already exists. Please choose another.");
usernameExists = true;
break;
}
}
if (usernameExists) {
continue; // start the loop over again to prompt for a new username
}
System.out.println("Enter a password:");
String password = input.nextLine();
// store the new user's credentials
usernames[count] = username;
passwords[count] = password;
count++;
System.out.println("Sign up successful!");
System.out.println("Do you want to sign up another user? (y/n)");
String choice = input.nextLine();
if (choice.equalsIgnoreCase("n")) {
break; // exit the loop if the user chooses not to sign up another user
}
}
// display all signed up users
System.out.println("All signed up users:");
for (int i = 0; i < count; i++) {
System.out.println(usernames[i] + " - " + passwords[i]);
}
}
}