forum

home / developersection / forums / how to use the scanner class in java?

How to use the Scanner class in java?

Anonymous User 2193 04-Oct-2013

I was doubting how, I could read input from the console using the Scanner class?

here's some code:

Scanner ob=new Scanner(System.in);
System.out.println("Enter your username: ");
String username=ob.nextLine();
System.out.println("Enter the value of a");
int a=ob.nextInt();

So basically all I want to do is have the scanner read an input for the username, and assign the input to a String variable.

Thanks!


Updated on 04-Oct-2013

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By