Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to add it to this code

Java
char input;
String state = in.next();
 input = state.charAt(0);
 do
 {
     System.out.println("Please enter a command type:");
 }while(!input);
Posted
Updated 4-Nov-12 11:35am
v2

Nope, there is not. However, if the string input is empty then the charAt method throws the IndexOutOfBoundsException (see the documentation[^]).
What are you trying to do?
 
Share this answer
 
Comments
diego14567 4-Nov-12 17:38pm    
im trying to make it loop if the input is not within the range of a-g
CPallini 4-Nov-12 17:46pm    
then replace while (!input) with while (input < 'a' || input > 'g').
try this
Java
Scanner in=new Scanner(System.in);
		char ch ;
		do{
			System.out.println("Enter the a character");
		try{
			ch= in.nextLine().charAt(0);
			System.out.println("Char: "+ch);			
		}
		catch (IndexOutOfBoundsException e) {
		      ch = 'z';
		}			
		}while(ch < 'a' || ch > 'g');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900