Search Header Logo
PROG06 - ARITHMENTIC OPERATORS AND EXPRESSIONS

PROG06 - ARITHMENTIC OPERATORS AND EXPRESSIONS

Assessment

Presentation

Other

11th Grade

Practice Problem

Medium

Created by

Ana Dupla

Used 7+ times

FREE Resource

48 Slides • 12 Questions

1

media

Computer P rogramming I

2

media

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

media

R E V I E W

4

media

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

media

A Sample Java A pplication P rogram

6

media

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

media

L et us have some
mathematical exercises!

8

media

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

media

A R I T H M E T I C OP E R A T OR S

15

media

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

media

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

media

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

media

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

media

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

media

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

media

Type in Java Language

Result:

2 + 5 = 7

2 * 7 = 14

5 / 2 = 2

34 % 5 = 4

22

media

Type in Java Language

Result:

5.0 + 3.5 = 8.5

16.4 - 5.2 = 11.2

34.5 / 6.5 = 5.3076923076923075

23

media

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

media

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

media

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

media

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

media

Can you use operators with both
integral and floating-point data
types?

YES

31

media

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

media

T Y P E CON V E R SI ON (CA ST I N G)

-

Syntax:

(data_typename) expression

33

media

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

media

Type in Java L anguage

Result:

(int) (7.9) = 7

(double) (15/2) = 7.0

(int) (7.8 + (double) (15) / 2) = 15

35

media

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

media

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

media

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

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?

39

Open Ended

Question image

40

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?
4
3

41

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?

42

Open Ended

Question image

43

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?
6
3

44

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?

45

Open Ended

Question image

46

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?
8
7

47

media

L E T U S T R Y ! E V A L U A T E .

What is the OUTPUT?

48

Open Ended

Question image

49

media

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

media

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

media

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

media

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

media

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

media

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

media

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

media

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);

media

Computer P rogramming I

Show answer

Auto Play

Slide 1 / 60

SLIDE