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

Recommended Answers

All 9 Replies

Scanner has no definition of method getChar.

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

You can use scanner.next() it returns string, but you can convert it to char.

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 :)

actually i found the answer

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

thanks guys ;)

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

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

I hope it helps...:)

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....

@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.

Member Avatar for ztini

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.