0% found this document useful (0 votes)
11 views4 pages

03 Lesson - Basic Input Output

This lesson focuses on elementary programming concepts, specifically declaring variables using numeric data types and performing arithmetic operations. It covers integer and floating-point literals, the use of operators, and exponent operations using the pow function in Java. The document includes examples, exercises, and assessments to reinforce the learning objectives.

Uploaded by

j2cvpthc7h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

03 Lesson - Basic Input Output

This lesson focuses on elementary programming concepts, specifically declaring variables using numeric data types and performing arithmetic operations. It covers integer and floating-point literals, the use of operators, and exponent operations using the pow function in Java. The document includes examples, exercises, and assessments to reinforce the learning objectives.

Uploaded by

j2cvpthc7h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1

Lesson 3 – Elementary Programming


Goal(s):
● To declare variables using numeric data types

● To write integer literals, floating-point literals, and literals in scientific notation

● To perform operations using operators +, - , * , /, and %

● To perform exponent operations using the pow(a,b) function

Minds On…

Calculate the perimeter and area of a circle with radius 10 cm.


Action …
Primitive Data Types and Operations
Java has a variety of numeric types for integers and floating-point numbers with operators +, -
, *, /, and %.
The primitive data types are summarized in the following table. Please ignore the date types boolean
and char for the time being as they are non-numeric.

Table Source
Note: In this course, we’ll be using mostly int and double as numeric data types.

Numeric Operators
The operators for numeric data types include the standard arithmetic operators: addition (+),
subtraction (–), multiplication (*), division (/), and remainder (%), as shown in Table 2.2.
The operands are the values operated by an operator.

Modulus is very useful in programing. For example, an even number % 2 will always result in 0 and an
off number % 2 will always result in 1. So you use this property to determine whether a number is
even or odd.

If today is Saturday, it will be Saturday again in 7 days. Suppose you and your friends are going to
meet in 10 days. What day is in 10 days? You can find that day is Tuesday using the following
expression:
5
Exponent Operations
To write bn in C++, we use Math.pow(b, n). For example,

System.out.println(Math.pow(2.0,3)); //Displays 8.0

System.out.println(Math.pow(4.0,0.5)); //Displays 2.0

Note that you could also use Math.sqrt(4.0) to compute the same result as above.

System.out.println(Math.pow(2.5,2)); //Displays 6.25

System.out.println(Math.pow(2.5,-2)); //Displays 0.16

Assessment
1. Which of the following are the same as 52.534?

5.2534e+1, 0.52534e+2, 525.34e-1, 5.2534e+0


2. If today is Tuesday, what will be the day in 100 days? Show how you solved this.
3. What is the result of 25 / 4? How would you rewrite the expression if you wished the result
to be a floating-point number (decimal)?
4. Show the result of the following:

5. Are the following statements correct? If so, show the output.


6. Write a statement to display the result of 23.5.
7. Suppose m and c are integers. Write a Java expression for mc 2 to obtain a floating-point
result.
8. Word matching exercise

9. Which of the following data types require the most amount of memory?

10. What is the result of (4 + 1) * ((5 - 2) / 2)?

You might also like