'F' → Fullscreen
System.out.println()
.
public class Program { public static void main(String[] args) { // Addition System.out.println("I'm adding 2 and 1. The result is:"); System.out.println(2 + 1); System.out.println();
System.out.println("Adding $1000 and $500.96 gives us:"); System.out.println(1000 + 500.96); System.out.println();
// Subtraction System.out.println("I have 3 apples, and I eat one. Now, I have:"); System.out.println(3 - 1); System.out.println();
// Multiplication System.out.println("I'm 30 years old. In months, that's: "); System.out.println(30 * 12); System.out.println();// }}
public class Program { public static void main(String[] args) { // Addition System.out.println("I'm adding 2 and 1. The result is:"); System.out.println(2 + 1); System.out.println();
System.out.println("Adding $1000 and $500.96 gives us:"); System.out.println(1000 + 500.96); System.out.println();
// Subtraction System.out.println("I have 3 apples, and I eat one. Now, I have:"); System.out.println(3 - 1); System.out.println();
// Multiplication System.out.println("I'm 30 years old. In months, that's: "); System.out.println(30 * 12); System.out.println();
// Division with integers and doubles System.out.println("If we divide 8 pizza slices between 2 people, each person gets:"); System.out.println(8 / 2); System.out.println();
System.out.println("Dividing $100 among 6 people gives each person:"); System.out.println(100.0 / 6); System.out.println("Without fractional amounts, each person gets:"); System.out.println(100 / 6); System.out.println();
// Remainder using the mod operator System.out.println("After dividing $100 among 6 people, the leftover cents are:"); System.out.println(100 % 6); System.out.println();// }}
public class Program { public static void main(String[] args) { // Addition System.out.println("I'm adding 2 and 1. The result is:"); System.out.println(2 + 1); System.out.println();
System.out.println("Adding $1000 and $500.96 gives us:"); System.out.println(1000 + 500.96); System.out.println();
// Subtraction System.out.println("I have 3 apples, and I eat one. Now, I have:"); System.out.println(3 - 1); System.out.println();
// Multiplication System.out.println("I'm 30 years old. In months, that's: "); System.out.println(30 * 12); System.out.println();
// Division - Quotient and remainder // Quotient System.out.println("If we divide 8 pizza slices between 2 people, each person gets:"); System.out.println(8 / 2); System.out.println();
System.out.println("Dividing $100 among 6 people gives each person:"); System.out.println(100.0 / 6); System.out.println("Without fractional amounts, each person gets:"); System.out.println(100 / 6); System.out.println();
// Remainder using the modulus, or mod, operator System.out.println("After dividing $100 among 6 people, the leftover cents are:"); System.out.println(100 % 6); System.out.println();
// Order of operations System.out.println("The expression 4 * 10 + 12 equals:"); System.out.println(4 * 10 + 12); System.out.println("The expression 4 * (10 + 12) equals:"); System.out.println(4 * (10 + 12));// }}
Your program output should something similar to the sample output below.
I'm adding 2 and 1. The result is:3
Adding $1000 and $500.96 gives us:1500.96
I have 3 apples, and I eat one. Now, I have:2
I'm 30 years old. In months, that's:360
If we divide 8 pizza slices between 2 people, each person gets:4
Dividing $100 among 6 people gives each person:16.666666666666668Without fractional amounts, each person gets:16
After dividing $100 among 6 people, the leftover cents are:4
The expression 4 * 10 + 12 equals:52The expression 4 * (10 + 12) equals:88
You may write your reflection answers as comments at the bottom of your code.
/
operator and the %
operator, and when would you use each one? Use an example from the
lesson to support your answer.
4 * 10 + 12
and 4 * (10 + 12)
produce different results. Why is it important to use parentheses
in an expression, and what do they do?
Submit your activity and reflection answers to the appropriate dropbox.