Java scanner class

Discussion in 'Mac Programming' started by yg17, Sep 11, 2005.

  1. yg17 macrumors G5

    yg17

    Joined:
    Aug 1, 2004
    Location:
    St. Louis, MO
    #1
    In my java class, we have to use the Scanner class thingy to get user input. I need to read in a char from the keyboard, and I've been looking over the methods for the class, and it seems to have a method to get everything except a char. Does anyone know how to accomplish this? Thanks
     
  2. Dave the Great macrumors regular

    Joined:
    Jan 27, 2004
    #2
    There are a few ways.

    One way would be to use the charAt method.
    So something like -
    Scanner scanner = new Scanner(System.in);
    char character = scanner.next().charAt(0);

    Or you could use the useDelimiter method with \w to check for a character.

    Hope this helps.
     
  3. ShaunJava macrumors newbie

    Joined:
    Sep 20, 2005
    #3
    Scanner Class Trouble

    I am a new java user. I downloaded java 5.0 and am using jGrasp 1.8.3. Old programs work except for those using Scanner Class. Here are hte errors I am getting:
    HourConversion.java:6: cannot resolve symbol
    symbol : class Scanner
    location: package util
    import java.util.Scanner;
    ^
    HourConversion.java:10: cannot resolve symbol
    symbol : class Scanner
    location: class HourConversion
    static Scanner console = new Scanner(System.in);
    ^
    HourConversion.java:10: cannot resolve symbol
    symbol : class Scanner
    location: class HourConversion
    static Scanner console = new Scanner(System.in);
    ^
    3 errors

    ----jGRASP wedge: exit code for process is 1.
    ----jGRASP: operation complete.

    Anyone else have trouble with this? Any suggestions?
     
  4. Dave the Great macrumors regular

    Joined:
    Jan 27, 2004
    #4
    If you have no issues with pre 5.0 code, then I would assume you either don't have 5.0 installed correctly on you system or JGrasp is not using 5.0.

    Well, I haven't used JGrasp, but there should be an option for you to choose what jdk you want to compile against.

    Or you could check on your mac for your java preferences to verify that 5.0 is above any other version that you might have installed. You might have installed 5.0 on your system, but if a program can use multiple versions, it will call the one that is on top.
     
  5. MacRumoron macrumors 6502

    Joined:
    Sep 6, 2005
    #5
    I had same problem

    I had that exact problem and i found this site: http://www.people.virginia.edu/~apf8b/CSpage/javaonmacs.html

    After following the instructions and launching jGrasp, the scanner class worked fine :p
     

Share This Page