This repository was archived by the owner on Jan 23, 2019. It is now read-only.
forked from ga-adi/expressions-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpressions.java
More file actions
157 lines (109 loc) · 3.87 KB
/
expressions.java
File metadata and controls
157 lines (109 loc) · 3.87 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Expressions Homework
*/
// Part 1: Order Of Operations
// ---------------------------
/* The mathematics Order of Operations:
Multiply and divide from left to right.
Add and subtract from left to right.
* /
// Part 2: Operators
// ---------------------------
/*
Summary of Operators
The following quick reference summarizes the operators supported by the Java programming language.
Simple Assignment Operator
= Simple assignment operator
Arithmetic Operators
+ Additive operator (also used
for String concatenation)
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator
Unary Operators
+ Unary plus operator; indicates
positive value (numbers are
positive without this, however)
- Unary minus operator; negates
an expression
++ Increment operator; increments
a value by 1
-- Decrement operator; decrements
a value by 1
! Logical complement operator;
inverts the value of a boolean
Equality and Relational Operators
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Conditional Operators
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for
if-then-else statement)
Type Comparison Operator
instanceof Compares an object to
a specified type
Bitwise and Bit Shift Operators
~ Unary bitwise complement
<< Signed left shift
>> Signed right shift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR
*
*/
// Operators Warm-Up
// 1) Add 42 + 1
int result1 = (42 + 1);
System.out.println(result);
// 2) Multiply 0 by 981 and then add 68 times 8
int result2 = (0 * 981) + (68 * 8);
System.out.println(result2);
// 3) Add 3.14 to 0.09 and then remove 12 from the total
int result3 = (3.14 + 0.09) - 12;
System.out.println(result3);
// 4) Divide 89 by 4 to show only the remainder
int result4 = (89 % 4);
System.out.println(result4);
// 5) Subtract 5.16 from 66.7128 and divide the results by 5
int result5 = (66.7128 - 5.15) / 5;
System.out.println(result5);
// Part 3: Formulae / Geometry
// ---------------------------
// Express how to find the area of a circle as an expression
area = (Math.PI * r * r);
System.out.println(area);
// Express the pythagorithm theorum as an expression - c is diagonal side of a right triangle
(a*a) + (b*b) = (c*c)
// Express how to find the area of a triangle as an expression, b = base; h = height
int area = 1/2(bh);
System.out.println(area);
// Express how discover the volume of a cube, length = 2
int vol = l*l*l;
System.out.println(vol);
//or wher n = 3....
System.out.println("2 to the power of " + n + " = " + Math.pow(2, n));
// Express how to find out how many milliseconds are in 14 minutes; 1 minute = 60000 milliseconds
number = (14 * 60000);
System.out.println(number);
// Part 4: Bonus
// ---------------------------
//Express how to calculate if a number equal in value to one third of another number
If {
number1 == (1/3) * number2
}
else {
System.out.println(number1 + "is not equal to 1/3 of " + number2);
}
//Express two linear equations that are equal to each other
4x + 3 = y
and y = 3 + 4x
//Express how to discover the slope of a line; slope = rise/run
int slope = (y^2 − y^1) / (x^2 − x^1)
System.out.println(slope);