Given a number

Examples:

- If n = 150, then display Bigger.
- If n = 40, then there should be no display.
- If n = 100, then there should be no display.

Given a number

Examples:

- If n = 150, then display Bigger.
- If n = 40, then display Not Bigger.
- If n = 100, then display Not Bigger.

Given two numbers

Examples:

- If a = 3 and b = 2, then display 3.
- If a = 5 and b = 7, then display 7.
- If a = 4 and b = 4, then display 4.

Similarly, given two numbers

Examples:

- If a = 3 and b = 2, then display 2.
- If a = 5 and b = 7, then display 5.
- If a = 4 and b = 4, then display 4.

Given two numbers

Examples:

- If a = 3 and b = 2, then display 2 3.
- If a = 5 and b = 7, then display 5 7.
- If a = 4 and b = 4, then display 4 4.
- If a = 11 and b = 14, then display 11 14.
- If a = 15 and b = 8, then display 8 15.

Given a number

Examples:

- If n = 40, then display Even.
- If n = 41, then there should be no display.
- If n = 42, then display Even.
- If n = 43, then there should be no display.

Similarly, given a number

Examples:

- If n = 40, then there should be no display.
- If n = 41, then display Odd.
- If n = 42, then there should be no display.
- If n = 43, then display Odd.

Given a number

Examples:

- If n = 40, then display Even.
- If n = 41, then display Odd.
- If n = 42, then display Even.
- If n = 43, then display Odd.

For this problem, we will just compare the number n with 100 using the greater than operator. If n is greater than 100 then we display Bigger. The implementation is straightforward:

if (n>100) { System.out.println("Bigger"); }Note that we don't display anything if the condition is not met as specified in the problem.

For this problem, we again compare the number n with 100 using the greater than operator. If n is greater than 100 then we display Bigger. Otherwise we display Not Bigger. We use the else keyword to denote what should be done when the condition is not met.

if (n>100) { System.out.println("Bigger"); } else { System.out.println("Not Bigger"); }

We now make the problem slightly harder by comparing two arbitrary number. Again we use the greater than operator with an if statement. If a is greater than b, then we display a because a is bigger than b. Otherwise, we know that b is either equal or bigger than a. And so we display b if a is not greater than b.

if (a>b) { System.out.println(a); } else { System.out.println(b); }

Just for practice, we do the opposite condition. We use the less than operator and if statement in this case. If a is less than b then we display a because we know it is smaller than b. Otherwise we know b is less than a or at most equal than a. So we can confidently say b is smaller if the first condition is not met.

if (a<b) { System.out.println(a); } else { System.out.println(b); }

Now we make it slightly harder than the last example. We need to display the smaller number first followed by the bigger one.

if (a<b) { System.out.println(a + " " + b); } else { System.out.println(b + " " + a); }As shown in the code above, if a is less than b then we know a is smaller than b, and so we display it first followed by b. Otherwise, we reverse the order because b is at least equal to a or even smaller.

To solve this problem, we need to understand the operator

Examples:

- 1%2 is 1
- 2%2 is 0
- 3%2 is 1
- 4%2 is 0
- 5%2 is 1
- 6%2 is 0
- 7%2 is 1
- 8%2 is 0
- 9%2 is 1
- 10%2 is 0

if (n%2==0) { System.out.println("Even"); }

Similar to the Even problem in 1.6, we just check if remainder is 1 rather than 0. Hence the solution below:

if (n%2==1) { System.out.println("Odd"); }

Solution to this is like combining what we learned in 1.2, 1.6 and 1.7. We just check if the remainder of n divided by 2 is 0 to know if we should display Even. if not met, we know it is odd.

if (n%2==0) { System.out.println("Even"); } else { System.out.println("Odd"); }