Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class trial {
- public static void main(String args[])
- {
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the number");
- int a= src.nextInt();
- int b=a;
- int n,n1,count=0;
- while(a>0)
- {
- n=a%10;
- count++;
- //System.out.println(n);
- a=a/10;
- }
- int arr[]=new int[count];
- int i=0;
- while(b>0&&count>=0)
- {
- n1=b%10;
- arr[i]=n1;
- b=b/10;
- i++;
- }
- for(int j=0;j<count;j++)
- {
- System.out.println("Position "+j+" "+arr[j]);
- }
- String arr2[]=new String[count];
- //int m=count-1;
- int m=0;
- for(int k=0;k<count;k++)
- {
- //for(int m=count-1;m>=0;m--)
- //{
- arr2[m]=String.valueOf(arr[k]);
- m++;
- //}
- }
- for(int p=0;p<count;p++)
- {
- System.out.println(arr2[p]);
- }
- String collector="";
- for(int q=0;q<count;q++)
- {
- collector=collector+arr2[q];
- }
- System.out.println(collector); //In string form now
- int ans=Integer.parseInt(collector);
- System.out.println("The final reversed number in Int form is "+collector);
- /*ans++; //to check
- System.out.println("Adding to check "+ans);*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement