-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArithmeticOperations.java
More file actions
31 lines (30 loc) · 1.3 KB
/
Copy pathArithmeticOperations.java
File metadata and controls
31 lines (30 loc) · 1.3 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
///Write a Java program to input two integers and display their sum, difference, product, quotient, and remainder.
import java.util.Scanner;
public class ArithmeticOperations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first integer: ");
int num1 = sc.nextInt();
System.out.print("Enter second integer: ");
int num2 = sc.nextInt();
int sum = num1 + num2;
int difference = num1 - num2;
int product = num1 * num2;
if (num2 != 0) {
int quotient = num1 / num2;
int remainder = num1 % num2;
System.out.println("\nResults:");
System.out.println("Sum = " + sum);
System.out.println("Difference = " + difference);
System.out.println("Product = " + product);
System.out.println("Quotient = " + quotient);
System.out.println("Remainder = " + remainder);
} else {
System.out.println("\nDivision and remainder cannot be performed (division by zero).");
System.out.println("Sum = " + sum);
System.out.println("Difference = " + difference);
System.out.println("Product = " + product);
}
sc.close();
}
}