inputting a char into a System.in Scanner (see code)

I have a scanner named console and I can input things like strings and numbers no sweat. I seem to be at a loss on how to enter a char, in the book I have it lists everything but char. So is it even possible or am I better off converting a string to a char? I have the entire program working except for this one microscopic detail...

import java.util.*;

public class excercise4_12

{private static Scanner console = new Scanner(System.in);

static public void main(String[] args)

{String accountNum = "";

char serCode;

System.out.println("Acount Number");

accountNum = console.nextLine();

System.out.println("Service Code");

serCode = console.next();

[732 byte] By [SoontirFela] at [2007-10-2 6:10:15]
# 1

Correct, the Scanner class doesn't have a nextChar() method. You can see all the methods from the Scanner class in their docs:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

If you want to read a char, you could read the complete line as a String and then get the first character of that String. Check the API of the String class to see how you can do that.

String docs: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

prometheuzza at 2007-7-16 13:10:55 > top of Java-index,Java Essentials,Java Programming...