Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static Scanner sc = new Scanner(System.in);
- public static String[] acc = new String[2];
- public static String key = "quit";
- public static void main(String[] args) {
- int a = 0;
- do {
- System.out.println("Would you like to log-in(1) or register[2]?");
- a = sc.nextInt();
- } while( a > 2 || a < 1);
- System.err.println("If you wish to close the terminal - type 'quit' in both username and password!");
- if(a == 1) Login();
- else if(a == 2) Register();
- }
- public static void Register() {
- System.out.print("Please enter a username: ");
- acc[0] = sc.next();
- System.out.print("Please enter a password: ");
- acc[1] = sc.next();
- if(acc[0].equals(key) || acc[1].equals(key)) System.err.println("Terminal Shut Down!");
- else {
- System.out.println("You have successfully registered, " + acc[0] + "!");
- Login();
- }
- }
- public static void Login() {
- String name, pass;
- System.out.print("Please enter username: ");
- name = sc.next();
- System.out.print("Please enter password: ");
- pass = sc.next();
- if(name.equals(acc[0]) && pass.equals(acc[1])) System.out.println("Welcome, " + acc[0] + "!");
- else if(name.equals(key) || pass.equals(key)) System.err.println("Terminal Shut Down!");
- else {
- System.out.println("Account not found! Please register!");
- Register();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement