A. Introduction

Other than printing out Christmas trees and graphics, System.out.println statement can also do simple calculations such as 3.1415*2*3. Numeric values such as "3.1415", "2" or "2.71828" are frequently used to compute. These numeric values are called "literals". Sometimes literals maybe fractions or power of tens. How would you write fractions or exponents? See if you can figure out from the table below.

B. Arithmetic equations are made of variables, literals and -- operators

You always need operators to compute. +, -, * are straight forward. But why 1729/10 = 172? what is 1729%10? See the table below:

C. Try:

What will happen if you run the following code?

class HelloWorld { public static void main(String[] args) { System.out.print("5+4 is:"); System.out.println(5+4); } }

What's the difference between *System.out.print("5+4 is:")* and *System.out.print(5+4 )?*

What's the difference between *System.out.print("5+4 is:")* and *System.out.println("5+4 is:")?
*

How can you print out the values of subtraction? multiplication? division?

What will this print out: *System.out.print(5/2); *why?

How to calculate decimals in Java?

Explain why 1729%10 is9, why 1729/10 is 172. In genheral, how can you get each digit of any integer? Explain.

If you write n%10, it will always print out the last digit of the variable, or n. If you write n/10, it will print out n without the last digit.