-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssociative.java
More file actions
29 lines (29 loc) · 851 Bytes
/
Associative.java
File metadata and controls
29 lines (29 loc) · 851 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
import java.util.Scanner;
public class Associative {
int a;
int b;
int c;
public Associative(int a, int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
public int firstTwo(){
return (a+b)*c;
}
public int lastTwo(){
return a+(b*c);
}
public static void main (String [] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int z = sc.nextInt();
Associative asc = new Associative(x, y, z);
int first = asc.firstTwo();
int last = asc.lastTwo();
System.out.println("Grouping the first two terms, (" + x + "+" + y +")" + "*" + z + " = " + first);
System.out.println("Grouping the last two terms, " + x + "+(" + y + "*" + z + ") = " + last);
sc.close();
}
}