console.nextChar(); ???

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2008
Posts: 3
Reputation: georgewb is an unknown quantity at this point 
Solved Threads: 0
georgewb georgewb is offline Offline
Newbie Poster

console.nextChar(); HELP PLEASE???

 
0
  #1
Nov 21st, 2008
Hi everyone,
I need your help please

What do i need to make my program read
the next character

using console.nextChar();

I've added the following:

import java.util.*;
static Scanner console = new Scanner(System.in);

and then in the main:

char ch;

ch = console.nextChar();

and when i compile i get this error::


cannot find symbol
symbol : method nextChar()
location: class java.util.Scanner
ch = console.nextChar();

can any 1 help me please??

thanks
Last edited by georgewb; Nov 21st, 2008 at 8:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: console.nextChar(); HELP PLEASE???

 
0
  #2
Nov 21st, 2008
Scanner has no definition of method getChar.
Last edited by Antenka; Nov 21st, 2008 at 8:45 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: georgewb is an unknown quantity at this point 
Solved Threads: 0
georgewb georgewb is offline Offline
Newbie Poster

Re: console.nextChar(); HELP PLEASE???

 
0
  #3
Nov 21st, 2008
Originally Posted by Antenka View Post
Scanner has no definition of method getChar.
so how can i make a program that reads the 1st character that the user enters:

for example:

if user enters :: A 1 2

ch= console.nextChar();
g = console.nextInt();
h= console.nextInt();

what can i use instead of nextChar()??
Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: console.nextChar(); ???

 
0
  #4
Nov 21st, 2008
You can use scanner.next() it returns string, but you can convert it to char.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: console.nextChar(); ???

 
0
  #5
Nov 22nd, 2008
just read it as String, convert it to an array of chars, or make a new Scanner class in which you define a nextChar() method
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: georgewb is an unknown quantity at this point 
Solved Threads: 0
georgewb georgewb is offline Offline
Newbie Poster

Re: console.nextChar(); ???

 
0
  #6
Nov 23rd, 2008
actually i found the answer

String a= console.next();
char b = (char)a.charAt(0);

thanks guys
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1
Reputation: ingrid2 is an unknown quantity at this point 
Solved Threads: 0
ingrid2 ingrid2 is offline Offline
Newbie Poster

Re: console.nextChar(); ???

 
0
  #7
Feb 22nd, 2009
mmm.... just in case you need this again, a better way to do it is:

variable = console.next().charAt(0);

I hope it helps...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC