[Solved] How do I select the first, second, or third digit from a String containing three digits? [closed]


You could try this.

String nbr = input.nextLine();    
int a=nbr.charAt(0)-'0';    
int b=nbr.charAt(1)-'0';    
int c=nbr.charAt(2)-'0';    

Also, you could use substring and parse the result Using Integer.parseInt

int a=Integer.parseInt(nbr.substring(0,1)); //Contains the leftmost digit

2

solved How do I select the first, second, or third digit from a String containing three digits? [closed]