Operations. Tasks

Author: Tatyana Milkina

1. Check if a Number is Even

  1. Create a program that tells whether an integer entered by the user is even or not.
  2. Use the Scanner class to input the number.
  3. If the user enters a non-integer, display an error message.

Solution on Patreon.

2. Minimum by Absolute Value

  1. Create a program that displays the smallest (by absolute value) of three real numbers entered by the user.
  2. Use the ternary conditional operator to calculate the absolute value.
  3. Input values using the Scanner class.

Solution on Patreon.

3. Garland: Part 1

You have a garland consisting of 32 bulbs. Each bulb can be either on or off. At the start of the program, randomly determine which bulbs are on. Implement the following methods:

  1. The blink method that makes the garland blink once (using the ~ operator);
  2. The run method that simulates a running light effect (using the << or >> operators);
  3. The isFirstLampOn method that checks whether the first bulb is on (using bit masking with &);
  4. A method that prints the current state of the garland. Use the method Integer.toBinaryString(a) to display the binary format.
  5. Use bitwise operations.

Watch the solution in the video.

Solution on Patreon.

4. Average of Numbers

Calculate the average value of three real numbers passed as command-line arguments. To convert from String to double, use Double.parseDouble(String s).

Solution on Patreon.

Курс 'Java для начинающих' на Udemy Курс 'Java для начинающих' на Udemy
Read also:
Comments