eemmrrkk
eemmrrkk

Reputation: 1700

Java Scanner get char

import java.util.Scanner;

public class myClass {
    public static void main(String[] args)
    {
        String[] exampleString;
        char expression;
        Scanner getExp = new Scanner(System.in);
        while(expression = getExp.next().charAt(0))
        {
           // myString will added by expression character
        }

    }
}

I tried it on Eclipse Mars but

expression = getExp.next().charAt(0) part gets error always.

I didn't understand that what is the error .

Previously i think on this link stackoverflow Scanner question

am i think wrong ?

Upvotes: 0

Views: 535

Answers (1)

Reimeus
Reimeus

Reputation: 159794

You probably want

while (getExp.hasNext()) {
    expression = getExp.next().charAt(0);
    ...
}

Upvotes: 2

Related Questions