
PROG06 - ARITHMENTIC OPERATORS AND EXPRESSIONS
Presentation
•
Other
•
11th Grade
•
Practice Problem
•
Medium
Ana Dupla
Used 7+ times
FREE Resource
48 Slides • 12 Questions
1
Computer P rogramming I
2
A R I T H M E T I C
OP E R A T OR S A N D
E X P R E SSI ON S
3
R E V I E W
4
Program example Problem:
Write a program that tak es as input given lengths
expressed in feet and inches. The program should then
convert and output the lengths in centimeters. A ssume
that the lengths given in feet and inches are integers.
Give the possible result of the program. A nswer the
following:
I nput:
Output:
P roblem A nalysis and A lgorithm D esign:
V ariables needed:
5
A Sample Java A pplication P rogram
6
L et us try!
A. Give the declaration for two variables called new and
old. Both variables are of type long . new is initialized
to 5. old is initialized to 100.
B. Write a Java assignment statement that will set the
value of the variable sample to the value of the variable
first added to the value of the variable second. first is
initialized to 50 and second is initialized to 2.50.
Assign the data type.
7
L et us have some
mathematical exercises!
8
L et us compute!
1. 10 + 10 = ___
2. 20 – 8 = ___
3. 55 x 5 = ___
4. 120 / 6 = ___
5. 305 / 2 = ___
9
Fill in the Blanks
Type answer...
10
Fill in the Blanks
Type answer...
11
Fill in the Blanks
Type answer...
12
Fill in the Blanks
Type answer...
13
Fill in the Blanks
Type answer...
14
A R I T H M E T I C OP E R A T OR S
15
E xpectations:
This lesson aims the following:
1. Demonstrate knowledge of Java syntax and codes.
2. Create executable java applications in accordance with Java
framework using Java expressions.
16
A R I T H M E T I C OP E R A T OR S
-
Addition (+)
-
Subtraction or negation ( -)
-
Multiplication (*)
-
Division (/)
-
Modulus or remainder (%)
17
A R I T H M E T I C E X P R E SSI ON S
A)-5
B)8 -7
C)3 + 4
18
A R I T H M E T I C E X P R E SSI ON S
-
Is constructed by using arithmetic operators and
numbers
-
The numbers and alphabetical symbols in the
expression is called OPERANDS
19
A R I T H M E T I C E X P R E SSI ON S
UNARY OPERATOR
- operators that have only
1 operand
BINARY OPERATOR
- operators that has 2
operand
20
E X A M P L E :
ARITHMETIC EXPRESSION
2 + 5
13 + 89
34 - 20
45 - 90
ARITHMETIC EXPRESSION
2 * 7
5 / 2
34 % 5
4 % 6
RESULT
7
102
14
-45
RESULT
14
2
4
4
21
Type in Java Language
Result:
2 + 5 = 7
2 * 7 = 14
5 / 2 = 2
34 % 5 = 4
22
Type in Java Language
Result:
5.0 + 3.5 = 8.5
16.4 - 5.2 = 11.2
34.5 / 6.5 = 5.3076923076923075
23
OR D E R OF P R E CE D E N CE
First: the unary operators: +, -, ++, --, and !
Second: the binary arithmetic operators: *,/, and %
Third: the binary arithmetic operators: + and
-
24
OR D E R OF P R E CE D E N CE
Using the precedence rules,
3 * 7 - 6 +2 * 5 / 4 + 6
(((3*7)-6)+((2*5)/4))+6
-
Evaluate from left to right, unless parentheses are
present.
-
Evaluate first *, then /, followed by -, lastly, +
25
L E T U S T R Y !
Convert each of the following mathematical formulas
to a Java Expression:
1. 3x
2. 3x+y
3. x+y
7
26
Word Cloud
3x
27
Word Cloud
3x+y
28
Open Ended
x+y
7
29
L E T U S T R Y !
What is the output of the following program lines?
double number = (1/3) * 3;
System.out.println(“(1/3) *3 is equal to “ + number);
30
Can you use operators with both
integral and floating-point data
types?
YES
31
T Y P E CON V E R SI ON (CASTI NG)
-
When a value of one data type is automatically
treated as another data type, an implicit type
coercion has occurred.
-
To avoid implicit type coercion, java provides for
explicit type conversion through the use of a cast
operator.
-
Cast operator also called type casting.
32
T Y P E CON V E R SI ON (CA ST I N G)
-
Syntax:
(data_typename) expression
33
T Y P E CON V E R SI ON (CA ST I N G)
-
Example:
(int ) (7.9) evaluates to 7
(double) (5+3) evaluates to 8.0
(int) (7.8 + (double) (15) / 2) evaluates to
(int) (7.8 + 7.5) = (int) 15.3 = 15
34
Type in Java L anguage
Result:
(int) (7.9) = 7
(double) (15/2) = 7.0
(int) (7.8 + (double) (15) / 2) = 15
35
I N CR E M E N T A N D D E CR E M E N T
OP E R A T OR S
INCREMENT OPERATOR ++ - adds one to the value
of a variable.
DECREMENT OPERATOR -- - subtracts one from the
value of a variable.
36
E xample:
int n = 1, m = 7;
n++;
System.out.println(“The value of n is changed to “ +
n);
m--;
System.out.println(“The value of m is changed to “ +
m);
37
W hat is the output of the given example?
The value of n is changed to 2
The value of m is changed to 6
38
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
39
Open Ended
40
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
4
3
41
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
42
Open Ended
43
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
6
3
44
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
45
Open Ended
46
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
8
7
47
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
48
Open Ended
49
L E T U S T R Y ! E V A L U A T E .
What is the OUTPUT?
7
7
50
Join our google classroom
TYPE THE CLASS CODE (B1):
aq5mmks
51
Join our google classroom
TYPE THE CLASS CODE (B2):
vwiwmct
52
PERFORMANCE ACTIVITY
53
P E R F OR M A N CE T A SK #2
Create a Program that output the following:
Math Problem:
Ellen had 380 legos but she lost 57 of them. How many legos does she have now?
Answer:
Ellen has now __________ legos.
54
P E R F OR M A N CE T A SK #3
Design / Create a program that includes 4 operators. It must have variable names and needs to be declared first. The output must be in complete sentence form.
55
WRITTEN ACTIVITY
56
W R I T T E N A CT I V I T Y
1. What is the output produced by the following lines
of program code?
int quotient, remainder;
quotient = 7/3;
remainder = 7%3;
System.out.println("quotient = " + quotient);
System.out.println("remainder = " + remainder);
57
W R I T T E N A CT I V I T Y
2. What is the output produced by the following code?
int result = 11;
result /= 2;
System.out.println("result is " + result);
58
W R I T T E N A CT I V I T Y
3. Given the following fragment to convert from degrees Celsius to
degrees Fahrenheit, answer the following questions:
double celsius = 20;
double fahrenheit;
fahrenheit = (9/5) * celsius + 32.0;
a. What value is assigned to fahrenheit?
b. Explain what is actually happening, and what the
programmer likely wanted.
c. Rewrite the code as the programmer intended.
59
W R I T T E N A CT I V I T Y
4. What is the output produced by the following lines
of program code?
int n = (int)3.9;
System.out.println("n == " + n);
60
W R I T T E N A CT I V I T Y
5. What is the output produced by the following lines
of program code?
int n = 3;
n++;
System.out.println("n == " + n);
n−−;
System.out.println("n == " + n);
Computer P rogramming I
Show answer
Auto Play
Slide 1 / 60
SLIDE
Similar Resources on Wayground
54 questions
Simple Harmonic Motion
Presentation
•
11th Grade
51 questions
Ekonomikas pirmais semestris.
Presentation
•
11th Grade
56 questions
Days Gone By
Presentation
•
11th Grade
53 questions
Present Perfect Subjunctive
Presentation
•
11th - 12th Grade
56 questions
Passive Voice B2.3
Presentation
•
11th Grade
50 questions
Micro-Enterprise Review
Presentation
•
11th - 12th Grade
55 questions
Punctuation Lesson
Presentation
•
KG
56 questions
R2 4A Test
Presentation
•
11th Grade
Popular Resources on Wayground
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
10 questions
Identify Fractions, Mixed Numbers & Improper Fractions
Quiz
•
3rd - 4th Grade
Discover more resources for Other
10 questions
Fact Check Ice Breaker: Two truths and a lie
Quiz
•
5th - 12th Grade
10 questions
Video Games
Quiz
•
6th - 12th Grade
15 questions
Memorial Day Trivia
Quiz
•
KG - 12th Grade
12 questions
Name that Candy
Quiz
•
KG - 12th Grade
20 questions
Guess The App
Quiz
•
KG - Professional Dev...
30 questions
K/H Final Review Part 1
Quiz
•
9th - 12th Grade
40 questions
NCFE Earth and Environmental Science Released Test
Quiz
•
9th - 12th Grade
22 questions
Revise and Edit Final Review 3
Quiz
•
8th - 12th Grade