Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yg17

macrumors Pentium
Original poster
Aug 1, 2004
15,028
3,003
St. Louis, MO
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
 

Dave the Great

macrumors regular
Jan 27, 2004
160
0
yg17 said:
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

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.
 

ShaunJava

macrumors newbie
Sep 20, 2005
1
0
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?
 

Dave the Great

macrumors regular
Jan 27, 2004
160
0
ShaunJava said:
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?

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.
 

MacRumoron

macrumors 6502
Sep 6, 2005
324
0
I had same problem

ShaunJava said:
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?

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.