in JavaScript Technology

Registration Form: Linking to login form Java

The user has a registration form which is running and is good but there is a problem with looping the registration form when entering an existing user. The following is the code

import java.util.*;
import java.io.*;
public class reg{
     public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Register");
                System.out.println("NOTE: This Is Just A Trial");
                System.out.println("NOTE: Password Must Be Integers Only");
                System.out.printf("Username: ");
                String user = input.next().toUpperCase();
                System.out.printf("Password: ");
                String pass = input.next();
                System.out.printf("Confirm Password: ");
                String conf = input.next();
                int length = pass.length();
                int passInt = Integer.parseInt(pass);
                int confInt = Integer.parseInt(conf);
                if(length < 6)
                    System.out.println("Password Should Be Greater Than 6 digits and Lower Than 11 Digits");
                else
                {
                if(passInt == confInt)
                {
                Scanner z = null;
                try{
                z = new Scanner(new File("userpass.txt"));
                boolean checkname = false;
                while(z.hasNext())
                {
                String a = z.next();
                int b = z.nextInt();
                if(a == null ? user == null : a.equals(user))
                checkname = true;
                }
                if(checkname)
                System.out.println("Username is already exists and used, please type another one");
                else
                {
                Formatter x = null;
                try{
                FileWriter f = new FileWriter("userpass.txt", true);
                x = new Formatter(f);
                x.format("%s %s%n",user.toUpperCase(),pass);
                System.out.println("You registered succesfully");
                x.close();
                }
                catch(Exception e)
                {
                e.printStackTrace();
                }
                }
                }                    
                catch(Exception e){}
                }
                else
                    System.out.println("Password Do Not Match");
                }
     }
}

Click here to view original web page at stackoverflow.com