Users Pricing

forum

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

How to use the Scanner class in java?

Anonymous User 2269 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!


I am a content writter !


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md