CodeGym /Java Course /Java Multithreading /Practice using bitwise operators

Practice using bitwise operators

Java Multithreading
Level 10 , Lesson 8
Available

"Hi, Amigo!"

9
Task
Java Multithreading, level 10, lesson 8
Locked
A new way to swap
In the Pair class, implement the swap method, which should swap the values of x and y. You can only use the following operations: 1) Exclusive or. 2) Assignment. 3) Exclusive-or assignment. Don't leave any comments. Don't change the rest of the code.
9
Task
Java Multithreading, level 10, lesson 8
Locked
Let's find the highest power of 2
Implement the maxPowerOf2 method, which should return the highest power of 2 that fits into the passed number. The maxPowerOf2 argument can only be a positive integer. Use only the following operations: 1) Bitwise shifts. 2) Bitwise OR. 3) Bitwise AND. 4) Bitwise unary NOT.
9
Task
Java Multithreading, level 10, lesson 8
Locked
Make one code change
Make one change to the program so that the output is always "ABC", even if null values are passed to the doSomething method. Don't change or add string literals. Don't change the lines that display data on the screen. Don't add setters.
18
Task
Java Multithreading, level 10, lesson 8
Locked
Derive a specific number
Implement the createExpression(int number) method. The createExpression method has one parameter called number. This parameter is a number from 1 to 3000 inclusive. You need to display an arithmetic expression whose result is number.
Comments (7)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Justin Smith Level 41, Greenfield, USA, United States
25 July 2022
"Make One Code Change" is a very weird task for two reasons. First, you have three similarly-structured sections of code (for A, B, and C), and in theory they should all do the same thing with their respective classes. So you play the Where's Waldo game and sure enough, there is something different in one of them. But the problem is that you can't correct what appears to be an error, because of the rules of the task, so instead you must compensate by changing something elsewhere. The other reason it's weird is that when you get it wrong on the first try, the validation literally tells you which line to change and how to change it. There is no reason anyone should take more than 2 tries on this task.
matemate123 Level 50, Kraków, Poland
9 August 2023
Yes, it's helpful when you did this task fresh after theory on previous lesson. Then you remember about lazy evaluation and it's fun task :)
BlueJavaBanana Level 37
5 December 2020
Are people truly beng honest here? These tasks are EASY?!!! How many people sneaked a look at a solution, copied and pasted just to pass? I'll wager more than people care to admit!
Justin Smith Level 41, Greenfield, USA, United States
25 July 2022
The last task before the last lesson does give you a pretty good crash course in how to think with bitwise operators, though. At first I looked at the swap one and thought "how is this even possible" but thinking about the numbers in their binary forms helps a lot.
fzw Level 41, West University Place, United States
25 May 2020
This should be helpful for last task: https://www.youtube.com/watch?v=DLfO_6sTvjo
fzw Level 41, West University Place, United States
25 May 2020
"find the highest power of 2" is exactly the same as "bit operators" task in Lecture 6, despite they are expressed in different ways!!
Justin Smith Level 41, Greenfield, USA, United States
25 July 2022
Yeah, honestly I think they might have restructured this part of the course at some point and forgot when moving it to be after the previous page, they still left the old one in place.