Operators. Tasks
1. Even or Odd
- Pass a number as a program argument.
- If the number is odd, print it.
- Use the if statement.
- Use Integer.parseInt() to convert the String to int.
Solution on Patreon.
2. Number between 0 and 10
- Use the Scanner class to read an integer.
- If the number is between 0 and 10, print “Positive number less than 10 or zero”. Otherwise, print “Positive number greater than 10 or negative”.
- Use the if-else statement.
Solution on Patreon.
3. Days of the Week
- Pass a number from 1 to 7 as a program argument.
- Print “Monday” if the number is 1, “Tuesday” for 2, etc. Print “Weekend” for 6 or 7.
- Use the if-else-if structure.
Watch the solution in the video.
Solution on Patreon.
4. Days of the Week with switch
Rewrite the previous task using the switch statement.
Watch the solution in the video.
Solution on Patreon.
5. Print 10 Lines Using while
Print 10 lines: “Task1”, “Task2”, ..., “Task10”. Use the while loop.
Watch the solution in the video.
Solution on Patreon.
6. Print Numbers Using do-while
Print all numbers from 1 to 100 divisible by 5 using the do-while loop.
Watch the solution in the video.
Solution on Patreon.
7. Print 5 Characters Using for
Print 5 characters in a row starting with ‘h’. Use the for loop.
Watch the solution in the video.
Solution on Patreon.
8. Garland, Part 2
Extend the Garland Part 1 task with the following:
- Use Scanner to input a number from 1 to 4.
- 1 – blink method, 2 – check first bulb, 3 – running light method, 4 – print garland state.
- Use switch statement for mode selection.
- Update blink method to blink 10 times (use for loop).
- Update running light method to run 10 times (use for loop).
Solution on Patreon.
9. Factorial
Calculate factorial using a for loop. Example:
n! = 1*2*...*n;
0! = 1;
5! = 1*2*3*4*5;
Generate a random number n between 0 and 5 using Math.random().
Solution on Patreon.

Please log in or register to have a possibility to add comment.