first sorry about my English(not my native language). I am new in programming (currently learning Java) and just finishing lecture about looping. I had a task to reverse random number from 1 to 9999, and got stuck with a bug zero:
example: 23100 output:132 and solution is 00132
Since I still don't know Arrays, convert to String(manipulation),object solution etc…. I couldn't find beginner solution for this problem.
Since this page helped me a lot, I decided to, maybe help someone: this is beginners solution to problem:
123 reverse 321
12300 reverse to 00321 // bug problem with zero solved
now I am still stuck with problem : 00123 and output 32100 not 321 but hope solve this soon
Best regards
import java.util.Scanner;
public class MP{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.print("enter number:\n");
int x=input.nextInt();
int temp=x;
int z;
while(temp>0){
z=temp%10;
if(z==0){
System.out.printf("%d",0);
}else{
System.out.printf("%d",z);
}
temp=temp/10;
}}}