Task 1 - Counting Twos.java Write a program that will ask the user to enter an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Thomas Calculus Early Transcendentals
ISBN: 9780321884077
13th Edition
Authors: Joel R Hass, Christopher E Heil, Maurice D Weir
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Consider a long cylindrical solenoid with diameter R, number of current loops N and length L through which a current I runs. Now (a) Use Ampre's law to calculate the magnetic field inside the...
-
Will precipitation occur when the following solutions are mixed? If so, write a balanced chemical equation for the reaction. (a) Na2CO3 and AgNO3 (b) NaNO3 and NiSO4 (c) FeSO4 and Pb(NO3)2.
-
Explain the typical influence of high vs low power distance on the following emphasis on formality, delegation of decision making.
-
Jim makes a deposit of $\$ 12,000$ in a bank account. The deposit is to earn interest annually at the rate of $9 \%$ percent for seven years. (a) How much will Jim have on deposit at the end of seven...
-
On average, there are 12 potholes per mile on a particular stretch of the state highway. Suppose the potholes are distributed evenly on the highway. a. Find the probability of finding fewer than two...
-
How do cultural differences impact collaboration in multinational teams, and what strategies can be employed to mitigate potential challenges ? Explain
-
Explanation of how the EYLF guides early childhood education and care pedagogy. (word count is 200 in text citation and APA 7th reference compulsory)
-
Suppose the quality control expert of question 30 knows from past experience that the number of defective light bulbs in a case of 10,000 has a population standard deviation of 221. She would like to...
-
Myers-Briggs Personality Types and Jungian Personality Types are two very popular descriptions of the material in this chapter. Using your search engine, access the Internet sites that refer to these...
-
Many salespeople, after being introduced to communication- style concepts, attempt to categorize each of their customers. They report that their relationships become mutually more enjoyable and...
-
Suppose you want to estimate a population proportion p. The total population consists of 1,000, your population consists of 100, and the sample proportion is .42. Find a 95 % confidence interval for...
-
Select several advertisements from a trade magazine. Analyze each one and determine which rational buying motives the advertiser is appealing to. Explain whether these advertisements also appeal to...
-
On January 1 2011 the Brunswick Hat Company adopted the dollar-value LIFO retail method. The following data are available for 2011. FO 1, 2011, the Brunswick Hat Company adopted the dollar data are...
-
Hardin Services Co. experienced the following events in 2016: 1. Provided services on account. 2. Collected cash for accounts receivable. 3. Attempted to collect an account and, when unsuccessful,...
-
The position vector along a trajectory expressed in terms of the scalar distance \(s\) from the origin is given by the relation \(\mathbf{r}=\mathbf{a} s^{2}+\mathbf{b} s+\mathbf{c}\), with the...
-
A particle moves on a predetermined trajectory with the equation of motion \(s(t)=k t^{2}\), with \(k\) constant and with magnitude of the acceleration equal to \(a=2 k\). Show by using (3.74) that...
-
A particle is constrained to move on a circular guideway of radius \(R=3.00 \mathrm{~m}\), on which it can slide without friction, according to the motion equation law \(s(t)=k t^{3}\), with \(k=2.0...
Study smarter with the SolutionInn App