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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With