943,793 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 23034
  • Java RSS
Nov 21st, 2008
0

console.nextChar(); HELP PLEASE???

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
georgewb is offline Offline
3 posts
since Nov 2008
Nov 21st, 2008
0

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

Scanner has no definition of method getChar.
Last edited by Antenka; Nov 21st, 2008 at 8:45 pm.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Nov 21st, 2008
0

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

Click to Expand / Collapse  Quote originally posted by Antenka ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
georgewb is offline Offline
3 posts
since Nov 2008
Nov 21st, 2008
0

Re: console.nextChar(); ???

You can use scanner.next() it returns string, but you can convert it to char.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Nov 22nd, 2008
0

Re: console.nextChar(); ???

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
Reputation Points: 935
Solved Threads: 356
Nearly a Posting Maven
stultuske is offline Offline
2,493 posts
since Jan 2007
Nov 23rd, 2008
0

Re: console.nextChar(); ???

actually i found the answer

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

thanks guys
Reputation Points: 10
Solved Threads: 0
Newbie Poster
georgewb is offline Offline
3 posts
since Nov 2008
Feb 22nd, 2009
0

Re: console.nextChar(); ???

mmm.... just in case you need this again, a better way to do it is:

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

I hope it helps...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ingrid2 is offline Offline
1 posts
since Feb 2009
Feb 26th, 2011
0

hifazat shah

hi buddyyyy.. i m ur new friend n recently join to this site...


u have seen ur problemm.... as u r still unable to get single character bu using scanner class....


you shud write:

char ch;
scanner scan = new scanner(System.in);
ch = scan.next(). charAt(0);


when u write the above statement u will able to read a character in java....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hifazat shah is offline Offline
1 posts
since Feb 2011
Feb 26th, 2011
0
Re: console.nextChar(); ???
@hifazat
hiiii 'buddyyyy ...
if a thread is solved, it means he did succees in getting the caracter.
don't revive threads that haven't been active for over two years, don't revive threads that are marked 'solved' and try to use some proper language.
English is chosen here, since most developers are familiar with it, but then try to keep it with correct grammar and vocabulary, since we don't all have english as our first language.
Reputation Points: 935
Solved Threads: 356
Nearly a Posting Maven
stultuske is offline Offline
2,493 posts
since Jan 2007
Feb 26th, 2011
0
Re: console.nextChar(); ???
Quote ...
English is chosen here, since most developers are familiar with it,
The company I work for has 6k developers in America/Europe and 12k developers in India. I would agree that most developers certainly are familiar with English, but from my experience it is broken, heavily-accented English...haha
Reputation Points: 29
Solved Threads: 44
Posting Whiz in Training
ztini is offline Offline
245 posts
since Jan 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Printing into screen
Next Thread in Java Forum Timeline: thread class for calculating the sum





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC