Q5 - Programming You are asked to write a Java program that takes a 3-digit number...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Q5 - Programming You are asked to write a Java program that takes a 3-digit number and performs some operations on it. The program asks the user to enter one positive number as integer consisting of 3-digits. The first digit is the least significant digit of the number and the fourth digit is the most significant digit (for example, for 321 first digit is 1, second digit is 2, and third digit is 3). Your program should do the following operations: Swap the first and third digits of the number, After applying the swapping operation divide the resulting number by 2 For example, if the user enters 145, your program should output 270. After the swapping operation you get 541, and after the division operation (541/2) you get 270 (you are applying integer division). Here is another example: when the user enters 110, your program must output 5 (011/2=5). You are NOT allowed to use the Integer.parseInt() method. Hint: For a 3-digit number abc, the equation 102 * b + 101* c + 10 * d = abc holds. Sample outputs of the program must look like as below. Enter a 3-digit number: 145 You get 270. Enter a 3-digit number: 100 You get 0. Answer: import java.util.Scanner; public class GamePlay { public static void main(String[] args) { Enter a 3-digit number: 110 You get 5. Enter a 3-digit number: 238 You get 416. Q5 - Programming You are asked to write a Java program that takes a 3-digit number and performs some operations on it. The program asks the user to enter one positive number as integer consisting of 3-digits. The first digit is the least significant digit of the number and the fourth digit is the most significant digit (for example, for 321 first digit is 1, second digit is 2, and third digit is 3). Your program should do the following operations: Swap the first and third digits of the number, After applying the swapping operation divide the resulting number by 2 For example, if the user enters 145, your program should output 270. After the swapping operation you get 541, and after the division operation (541/2) you get 270 (you are applying integer division). Here is another example: when the user enters 110, your program must output 5 (011/2=5). You are NOT allowed to use the Integer.parseInt() method. Hint: For a 3-digit number abc, the equation 102 * b + 101* c + 10 * d = abc holds. Sample outputs of the program must look like as below. Enter a 3-digit number: 145 You get 270. Enter a 3-digit number: 100 You get 0. Answer: import java.util.Scanner; public class GamePlay { public static void main(String[] args) { Enter a 3-digit number: 110 You get 5. Enter a 3-digit number: 238 You get 416.
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
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...
-
Serra do Mar Corporation manufactures and distributes leisure clothing. Selected transactions completed by Serra do Mar during the current fiscal year are as follows: Jan. 8 Split the common stock 3...
-
During the free fall of a rigid body (system), identify the interactions between the system and its surroundings.
-
calculate the six-month forward premium or discount for the Swiss franc versus the U.S. dollar. For simplicity, assume each month has 30 days. (XXX%) or (-XXX%) EXHIBIT 5.7 Exchange Rates Currencies...
-
If we have a model for the short rate \(r(t)\), show that (a) the zero coupon bond price can be calculated as: \[P(t, s)=\mathbf{E}_{t}\left[e^{\int_{t}^{s} r(u) d u}...
-
You are provided with the following information for Perkins Inc. for the month ended October 31, 2014. Perkins uses a periodic method for inventory. Instructions (a) Calculate (i) ending inventory ,...
-
PT Elyksion Communication is experiencing rapid growth. The company expects earnings and dividend growth of 15% over the next two years, 13% in the third year, and constant growth of 6% for the...
-
Howard Manufacturing's overhead at year-end was under applied by $5,800, a small amount given the firm's size. The year-end journal entry to record this amount would include what?
-
Consider the following rational expression. xy 6y + 5x 30 y - 25 Find the restricted values of y, if any, for the given rational expression. Separate multiple answers with a comma.
-
Below is the combinational circuit that implements the Boolean expression F. [8 marks] a- Write the equation of the output of gates 2 and 3. b- Suppose that a=0, b=0, c=0. What is the output value at...
-
The demand and supply of money may be estimated by the following equations: M d = 2,250 250i M s = 1,000 a) Calculate the equilibrium i and illustrate it diagrammatically. b) Calculate the new i...
-
An electric utility company determines the monthly bill by charging 80.1 cents per kilowatt-hour (kWh) used plus a base charge of $17.25 per month. Thus, the monthly charge is given by the function...
-
( A horizontal curve is designed for a two-lane road in a level terrain. The following data are known: Central angle (A): 50 degrees Design speed of 80 km/h Side friction factor = 0.12 Superelevation...
-
Multiple choice questions: 1) A high rate of employee turnover indicates that: A) Employees of the organization leave jobs frequently. B) Pay packages of employees are at par with that of industry....
-
Draw and label the E and Z isomers for each of the following compounds: 1. CH3CH2CH==CHCH3 2. 3. 4. CH,CH2C CHCH2CH Cl CH3CH2CH2CH2 CH CH2CCCH2CI CHCH3 CH3 HOCH CH CCC CH O-CH C(CH
-
Explain the building blocks of accounting: ethics, principles, and assumptions.
-
On May 1, 2025, Park Flying School Ltd., a company that provides flying lessons, was started with an investment of 45,000 cash in the business. Following are the assets and liabilities of the company...
-
The historical cost basis results in: a. initially recording assets at cost and adjusting when the current value changes. b. keeping activities of an entity separate and distinct from its owner. c....
Study smarter with the SolutionInn App