why the do-while couldnt return the main body when i did once.when I input n<2 and press enter, it stops and turns to error.
i dont know why?could i any one told me why and how to change it and is there another code to do this loop( instead do-while).thanks alot.
Here the code:
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
int Words=0;
int n=0;
do{{/color}
String Name=in.nextLine();
StringBuffer name= new StringBuffer(Name);
name.setCharAt(0,Character.toUpperCase…
for(int i=0;i<name.length();i++){
if(name.charAt(i)==' '){
name.setCharAt(i+1, Character.toUpperCase(name.charAt(i+1)))…
Words++;
}
}
String MiddleName= name.substring(Name.indexOf(' ')+1,Name.lastIndexOf(' '));
String FirstName=name.substring(0, Name.indexOf(' '));
String LastName=name.substring(Name.lastIndexOf… '),name.length());
System.out.println(name);
System.out.print(MiddleName+"\n");
System.out.print(FirstName+"\n");
System.out.print(LastName+"\n");
System.out.println("Words :"+ (Words+1));
System.out.print("Want more");
n=in.nextInt();
//System.exit(0);
} while (n<2);