Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

standard console input

Tags:

java

Good afternoon

I would just like to know the easiest way for standard Console input with java. When it come to int or double input for example in C# it is simple. What would the easiest way be of doing this in java.?

double a;
        Console.WriteLine("Please enter the value");

        a = double.Parse(Console.ReadLine());

        Console.WriteLine("thank you for entering " + a);

Kind regards Arian

like image 812
Arianule Avatar asked Nov 28 '11 15:11

Arianule


1 Answers

The direct translation is:

Scanner scan = new Scanner(System.in);
System.out.println("Please enter the value");
double i = Double.parse(scan.nextLine());
System.out.println("thank you for entering " + i);

But you can also use Scanner#nextDouble():

Scanner scan = new Scanner(System.in);
System.out.println("Please enter the value");
double i = scan.nextDouble();
System.out.println("thank you for entering " + i);
like image 151
MByD Avatar answered Oct 18 '22 20:10

MByD