RSS Forums RSS

console.nextChar(); ???

Please support our Java advertiser: Programming Forums
Thread Solved
Reply
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???

  #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 7:41 pm.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 173
Reputation: Antenka will become famous soon enough Antenka will become famous soon enough 
Solved Threads: 38
Antenka's Avatar
Antenka Antenka is offline Offline
Junior Poster

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

  #2  
Nov 21st, 2008
Scanner has no definition of method getChar.
Last edited by Antenka : Nov 21st, 2008 at 7: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  
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???

  #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  
Posts: 173
Reputation: Antenka will become famous soon enough Antenka will become famous soon enough 
Solved Threads: 38
Antenka's Avatar
Antenka Antenka is offline Offline
Junior Poster

Re: console.nextChar(); ???

  #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  
Posts: 705
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 83
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: console.nextChar(); ???

  #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  
Posts: 3
Reputation: georgewb is an unknown quantity at this point 
Solved Threads: 0
georgewb georgewb is offline Offline
Newbie Poster

Re: console.nextChar(); ???

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

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

thanks guys
Reply With Quote  
Posts: 1
Reputation: ingrid2 is an unknown quantity at this point 
Solved Threads: 0
ingrid2 ingrid2 is offline Offline
Newbie Poster

Re: console.nextChar(); ???

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Java Forum
Views: 1886 | Replies: 6 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:11 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC