-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplecalculation.java
More file actions
33 lines (26 loc) · 1.05 KB
/
Simplecalculation.java
File metadata and controls
33 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class SimpleCalculation {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter two numbers
System.out.print("Enter the first number: ");
double num1 = scanner.nextDouble();
System.out.print("Enter the second number: ");
double num2 = scanner.nextDouble();
// Perform basic arithmetic operations
double sum = num1 + num2;
double difference = num1 - num2;
double product = num1 * num2;
double quotient = num1 / num2;
// Display the results
System.out.println("Number 1: " + num1);
System.out.println("Number 2: " + num2);
System.out.println("Sum: " + sum);
System.out.println("Difference: " + difference);
System.out.println("Product: " + product);
System.out.println("Quotient: " + quotient);
// Close the scanner object
scanner.close();
}
}