Basic Operations
Part of the Fundamentals section of Coddy's Java journey — lesson 40 of 73.
Challenge
BeginnerAdd the basic arithmetic operations (addition, subtraction, multiplication, and division) on num1 and num2. Store the results in variables named sum, difference, product, and quotient, respectively. Print the results to the console using System.out.println in the following format:
Sum: [sum]
Difference: [difference]
Product: [product]
Quotient: [quotient]Try it yourself
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Calculator App");
Scanner scanner = new Scanner(System.in);
double num1 = scanner.nextDouble();
double num2 = scanner.nextDouble();
System.out.println("First number: " + num1);
System.out.println("Second number: " + num2);
}
}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