Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q5 - Programming You are asked to write a Java program that takes a 3-digit number and performs some operations on it. The program

image

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Concepts Late Objects

Authors: Cay S. Horstmann

3rd Edition

1119186714, 978-1119186717

More Books

Students also viewed these Programming questions

Question

6. How does an epigenetic change differ from a mutationpg99

Answered: 1 week ago