Operations. Tasks
1. Check if a Number is Even
- Create a program that tells whether an integer entered by the user is even or not.
- Use the Scanner class to input the number.
- If the user enters a non-integer, display an error message.
Solution on Patreon.
2. Minimum by Absolute Value
- Create a program that displays the smallest (by absolute value) of three real numbers entered by the user.
- Use the ternary conditional operator to calculate the absolute value.
- 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:
- The
blinkmethod that makes the garland blink once (using the~operator); - The
runmethod that simulates a running light effect (using the<<or>>operators); - The
isFirstLampOnmethod that checks whether the first bulb is on (using bit masking with&); - A method that prints the current state of the garland. Use the method
Integer.toBinaryString(a)to display the binary format. - 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
Please log in or register to have a possibility to add comment.