Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:21:32+00:00 2026-06-13T09:21:32+00:00

The homework problem is the user enters a number. Then you have to write

  • 0

The homework problem is the user enters a number. Then you have to write a program that reverses that order. So if the user enters 7364 you have to write a program that presents 4637 on the next line. I think I’ve figured out the solution but I’m not sure how to write it.

Since the last number is the first number in reverse order that means that if someone enters 7364 that means i want to get 4637. I have to write a program that multiplies 4 by 1000, 6 by 100, 3 by 10 and 7 by 1 then add those up to get 4637. I’m not not 100% sure how to do it. What’s messing me up is how to multiply one number by 1000, the next by 100, the next by 10 and the next by 1 then add those up.

import acm.program.*;
public class ReverseNumber extends ConsoleProgram{
    public void run(){

    int n = readInt("please enter any positive number: ");

    int total = 0;


    while ( n > 0){
    total = total + n % 10;    <----?
    n = n * 1000;         <----?
      }
    println("the reverse order is" + total); 

   }

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:21:34+00:00Added an answer on June 13, 2026 at 9:21 am

    This should work:

        total = 0;
        while (n > 0) {
            total = total * 10 + n % 10;
            n = n / 10;
        }
        println("the reverse order is " + total); 
    

    You don’t have to know how many digits there are in the original number, you’re iterating through all of them anyway. Here’s what happens:

    • When you get a new digit (n % 10), you multiply the result by 10 and add it to it. This way, you offset the digits in the result.
    • Then you eliminate the last digit (the one you added in the step before) from the original number by doing n / 10.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a homework problem where I have to make an inheritance program that
This is a homework assignment, I have to write a program that reads a
I have a homework question that says: Problem 1: Given the array [ 22
I have done a homework assignment, here is the problem statement: Your program should
I have a homework assignment that I am supposed to write a http server
I have a homework problem here I've been working on; here is the description:
Okay, so I have another question on a prolog homework problem I am struggling
I am doing homework but I have problem with non-RestFul routes. My spec is:
This is my homework, but please read my problem description first. I have to
I am learning Ruby and have to do some homework, but have problem with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.