-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBasicArithmetic.java
More file actions
53 lines (30 loc) · 902 Bytes
/
Copy pathBasicArithmetic.java
File metadata and controls
53 lines (30 loc) · 902 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
2.15 (Arithmetic) Write an application that asks the user to enter two integers, obtains them
from the user and prints their sum, product, difference and quotient (division). Use the techniques
shown in Fig. 2.7.
*/
package chapter2;
import java.util.Scanner;
public class BasicArithmetic{
public static void main(String[] args){
Scanner collector = new Scanner(System.in);
int a;
int b;
int sum;
int product;
int difference;
int quotient;
System.out.print("Enter a number: ");
a = collector.nextInt();
System.out.print("Enter another number: ");
b = collector.nextInt();
sum = a + b;
System.out.printf("Sum is %d%n", sum);
product = a * b;
System.out.printf("Product is %d%n", product);
difference = a - b;
System.out.printf("Difference is %d%n", difference);
quotient = a / b;
System.out.printf("Quotient is %d%n", quotient);
}
}