Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 - Counting Twos.java Write a program that will ask the user to enter an integer and calculate the power of two. Output
Task 1 - Counting Twos.java Write a program that will ask the user to enter an integer and calculate the power of two. Output the number of twos in this number. Input Enter an integer: 5 Enter an integer: 18 Output 2^5 = 32 2^18 = 262144 2^5 contains 1 twos 2^18 contains 2 twos Task 2 BeautifulDays.java Lily likes to play games with integers. She has created a new game where she determines the difference between a number and its reverse. For instance, given the number 12, its reverse is 21. Their difference is 9. The number 30 reversed is 3, and their difference is 27. She decides to apply her game to decision making. She will look at a numbered range of days and will only go hiking on a beautiful day. Write a program that will ask the user to enter three integers, i, j and k and determine the number of days in the range that are beautiful. The range of numbers is from i to j where 1 i 31 and 1 j 31. Beautiful days are defined as numbers within this range are divisible by k. Sample Input: 20 23 6 Sample Output: 2 Explanation: We perform the following calculations to determine which days are beautiful: Day 20 is beautiful because the following evaluates to a whole number: (20-02)/6=3 Day 21 is not beautiful because the following doesn't evaluate to a whole number: (21-12)/6=1.5 Day 22 is beautiful because the following evaluates to a whole number: (22-22)/6=0 Day 23 is not beautiful because the following doesn't evaluate to a whole number: (23-32)/6=1.5 Only two days, 20 and 22, in this interval are beautiful. Thus, we print 2 as our answer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started