Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (2.6k points)
I attempted to create a calculator, but I can not get it to work because I don't know how to get user input.

How can I get the user input in Java?

1 Answer

0 votes
by (46k points)

One of the easiest methods is to use a Scanner object as pursues:

import java.util.Scanner;

Scanner reader = new Scanner(System.in); // Reading from System.in

System.out.println("Enter a number: ");

int n = reader.nextInt(); // Scans the next token of the input as an int.

//once finished

reader.close();

Related questions

0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
0 answers

Browse Categories

...