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 8204683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:58:15+00:00 2026-06-07T07:58:15+00:00

Ok so I wrote a program which asks user to input a number and

  • 0

Ok so I wrote a program which asks user to input a number and then reverse it. I was successful in it however the program does not reverses numbers that end with a 0. for example if i enter 1234 it will print out 4321 however if i input 1200 it will only output 21. I tried converting the number that is to become output into string. Please help me understand where I am doing it wrong. Just remember I am a beginner at this :). Below is my code.

import java.util.*;
public class ReverseNumber
{
    public static void main (String [] args)
    {
        Scanner n = new Scanner(System.in);
        int num;
        System.out.println("Please enter the number");
        num = n.nextInt();
        int temp = 0;
        int reverse = 0;
        String str = "";
        System.out.println("The number before getting reversed " + num);
        while (num != 0)
        {
            temp = num % 10;
            reverse = reverse*10 + temp;
            num = num/10;
            str = Integer.toString(reverse);
        }
        //String str = Integer.toString(reverse);
        System.out.println("The reversed number is " + str);
    }
}
  • 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-07T07:58:16+00:00Added an answer on June 7, 2026 at 7:58 am

    You’re storing your reversed number as an int. The reverse of 1200 is 0021, but that’s just 21 as an int. You can fix it by converting each digit to a string separately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i had to write a program that asks for a user input (which
Can anyone help with this exersise? Write a program which asks the user for
I wrote a C program which reads a dataset from a file and then
I wrote a small program which frequently opens small, user text files and until
I wrote a program which uses a number of built in modules. The program
I wrote a simple program which takes a predefined number to a predefined power
I am currently trying to write a program which asks the user for a
I've written a special calculator which prompts the user for 2 numbers then displays
I have a program which I wrote in Java using Eclipse and then put
I wrote this short program which has a tiny GUI. Its supposed to allow

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.