Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of Scanner with primitive type char  RSS feed

 
Kelly Meehan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help using the instance of scanner to declare a primitive type char. So far I have declared and instantiated the scanner, and I tested the program using more basic primitive types (i.e. int, double, and short)....

System.out.println("Enter an int c")
int c = sc.nextInt();

System.out.println("Enter a double d")
double d = sc.nextDouble();

System.out.println("Enter a short e")
short e = sc.nextShort();

I just don't know what to use for char. Could anyone please help? Thanks.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not used the Scanner class, but if there's nothing standard, this might do

char x = sc.next().charAt(0);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!