Step 2 of 6
Calculating with input
Numbers read from the user work like any other numbers once they're converted. A common pattern: read, calculate, then print the result.
Scanner scanner = new Scanner(System.in);
int price = Integer.valueOf(scanner.nextLine());
int count = Integer.valueOf(scanner.nextLine());
int total = price * count;
System.out.println("Total: " + total);
12
4Total: 48Storing the result in its own variable (total here) gives it a name, which makes the program easier to read than one long line. It also lets you use the result more than once.