Java

Part 4 (More Single Loop Exercises) (a) Write a method powerOfTwo that takes an integer argument and prints to the console what power of 2 the given number is. If the number is not a power of 2, then simply print a message that says so. For example, powerOfTwo (64): 1/should print: “64 is 2 to the power of 6” powerOfTwo (73): 1/should print: “73 is not a power of 2” Note: you are not allowed to use any library functions! (b) Write a method numBackward that reverses the digits of a given integer (that is, an integer passed in as an argument). Use a single loop and modular arithmetic to accomplish this goal. Play around with ideas on paper first. After you reverse the digits, compare the number you got with the original argument and determine if the original argument is a palindrome. Your method should print a message to the screen that states the reversed number and whether or not it is a palindrome. For example numBackward (123456789) //should print: “backward: 987654321, not palindrome!” numBackward (123454321) //should print: “backward: 123454321, palindrome!” Show transcribed image text Part 4 (More Single Loop Exercises) (a) Write a method powerOfTwo that takes an integer argument and prints to the console what power of 2 the given number is. If the number is not a power of 2, then simply print a message that says so. For example, powerOfTwo (64): 1/should print: “64 is 2 to the power of 6” powerOfTwo (73): 1/should print: “73 is not a power of 2” Note: you are not allowed to use any library functions! (b) Write a method numBackward that reverses the digits of a given integer (that is, an integer passed in as an argument). Use a single loop and modular arithmetic to accomplish this goal. Play around with ideas on paper first. After you reverse the digits, compare the number you got with the original argument and determine if the original argument is a palindrome. Your method should print a message to the screen that states the reversed number and whether or not it is a palindrome. For example numBackward (123456789) //should print: “backward: 987654321, not palindrome!” numBackward (123454321) //should print: “backward: 123454321, palindrome!”

The post Part 4 Single Loop Exercises Write Method Poweroftwo Takes Integer Argument Prints Console Q26379575 appeared first on Nurses Den.