Getting Numbers
Part of the Fundamentals section of Coddy's Java journey — lesson 39 of 73.
Challenge
BeginnerModify the given code to get two numbers from the user and store them in variables named num1 and num2. Use the Scanner class and its nextDouble() method to read the numbers. After getting the numbers, print them to the console using System.out.println to verify the input in the following format:
First number: ...
Second number: ...Don't forget! Import the
Scannerlibrary at the top of your program in order to use it:import java.util.Scanner;
Try it yourself
public class Main {
public static void main(String[] args) {
System.out.println("Calculator App");
}
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 43Variables Part 2
ConstantsNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementTernary OperatorRecap - If ElseNested If - Else