Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,i have to do a program which reverses the numbers till the max,which is the user input.I managed to reverse it but when there is lower numbers then then it writes 01 02 03...which reversed is 10 20 30 which i dont need.How i get rid of the 0?
I appreciate any help.Thx in advance

Here is the code:

C#
static int input;
static int i;
static int j;
static int z;


public static void main(String [] args){

    System.out.println("Enter the max number:");
    int input = new Scanner(System.in).nextInt();

    for(i=1;i<=input;i++){
        j = i%10;
        z = i/10;
        System.out.print(" "+j+z);


    }

}
Posted
Comments
Maciej Los 15-Mar-15 9:29am    
Not clear what you want to achieve and what kind of issue do you have...
Sergey Alexandrovich Kryukov 15-Mar-15 10:19am    
Define "reverse". Your problem is not a problem, it's purely imaginary. If you don't want leading zero, just use "if" and don't output it. Do you understand that you are "reversing" not numbers, but strings? I cannot be sure that you even understood your assignment. As you failed to formally define what you are supposed to do (only gave an example), it's possible that you did not understand it yourself.
So, we can continue with that only after you write some formal and precise definition of the problem.
—SA

1 solution

That's the least of your problems...what happens if the user enters a three digit number? A four digit number?

Go back to your question from yesterday: Sum of reversed numbers[^] and re-read my solution - it explains you need a loop, yes? And implementing the loop to reverse the number will solve both problems!

You're not far off - you just need to think a little more...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900