public class BearOrShark { public static void main(String[] args) { int luck = 10; if((luck>10 ? luck++: --luck)<10) { System.out.print("Bear"); } if(luck<10) System.out.print("Shark"); } }
❌ A. Bear ❌ B. Shark ✅ C. BearShark ❌ D. The code will not compile because of line 4. ❌ E. The code will not compile because of line 6. ❌ F. The code compiles without issue but does not produce any output
Explanation: The code compiles and runs without issue, so options D and E are correct. Remember that only one of the right-hand ternary expressions will be evaluated at runtime. Since luck is not less than 10, the second expression, --luck, will be evaluated, and since the pre-increment operator was used, the value returned will be 9, which is less than 10. So the first if-then statement will be visited and Bear will be output. Notice there is no else statement on line 6. Since luck is still less than 10, the second if-then statement will also be reached and Shark will be output; therefore, the correct answer is option C.
public class BearOrShark { public static void main(String[] args) { int luck = 10; if((luck>10 ? luck++: --luck)<10) { System.out.print("Bear"); } if(luck<10) System.out.print("Shark"); } }
❌ A. Bear ❌ B. Shark ✅ C. BearShark ❌ D. The code will not compile because of line 4. ❌ E. The code will not compile because of line 6. ❌ F. The code compiles without issue but does not produce any output
Explanation: The code compiles and runs without issue, so options D and E are correct. Remember that only one of the right-hand ternary expressions will be evaluated at runtime. Since luck is not less than 10, the second expression, --luck, will be evaluated, and since the pre-increment operator was used, the value returned will be 9, which is less than 10. So the first if-then statement will be visited and Bear will be output. Notice there is no else statement on line 6. Since luck is still less than 10, the second if-then statement will also be reached and Shark will be output; therefore, the correct answer is option C.
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Secure video calling is in high demand. As an alternative to Zoom, many people are using end-to-end encrypted apps such as WhatsApp, FaceTime or Signal to speak to friends and family face-to-face since coronavirus lockdowns started to take place across the world. There’s another option—secure communications app Telegram just added video calling to its feature set, available on both iOS and Android. The new feature is also super secure—like Signal and WhatsApp and unlike Zoom (yet), video calls will be end-to-end encrypted.
What Is Bitcoin?
Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.