I am not sure what is wrong with my While Loop because if select ("Press 0 to edit info."), I will not get prompt for "Name" anymore.
Another thing is my exception does not work. I wanted to deny user from entering alphanumeric under "Mobile". Only numeric allowed here.
Pls advise. Tks.
import java.io.*;
import java.util.*;
public class Profile {
public static void main (String [] args) {
String name="",user="",pass="",add="",con="";
int done = 0;
int ch = 500;
Scanner scn = new Scanner(System.in);
while(done != 1){
System.out.println("Enter your profile\n");
System.out.print("Name:");
name = scn.nextLine();
System.out.print("Username:");
user = scn.nextLine();
System.out.print("Address:");
pass = scn.nextLine();
//try{
System.out.print("Mobile:");
con = scn.nextLine();
//}
/*catch ( InputMismatchException inputMismatchException )
{
System.err.printf( "\nException: %s\n", inputMismatchException );
scn.nextLine(); // discard input so user can try again
System.out.println("You enter nos. Please retry again.\n" );
} // end catch*/
System.out.println("");
System.out.println("Press 0 to edit info.");
System.out.println("Press 1 to save.");
System.out.println("Press 2 to quit w/o saving.");
System.out.print("Select a choice:");
ch = scn.nextInt(); //Read in user prompt (0, 1 or 2)
if (ch != 2)
done = ch;
else
done = 1;
}//End of while loop
if(ch!=2 ){
String info= "\r\n"+name+";"+user+";"+add+";"+con;
try {
PrintWriter out = new PrintWriter(new FileWriter("Profile.txt",true));
out.write(info);
out.close();
}
catch (IOException e) { }
}//if
System.out.println("Tks for registering.");
}
}//END