Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- System.out.println("Enter the number by which each digit has to be increamented");
- int inc=src.nextInt();
- int n,n2,count=0,i=0;
- while(a>0)
- {
- n=a%10;
- count++;
- a=a/10;
- }
- int arr[]=new int[count];
- while(b>0)
- {
- n2=b%10;
- arr[i]=n2;
- b=b/10;
- i++;
- }
- /*for(int j=0;j<count;j++)
- {
- System.out.println("position "+j +" has value "+arr[j]);
- }*/
- int arr2[]=new int[count];
- int m=count-1;
- for(int k=0;k<count;k++)
- {
- arr2[k]=arr[m];
- m--;
- }
- /*for(int p=0;p<count;p++)
- {
- System.out.println("position "+p +" has value "+arr2[p]);
- }*/
- for(int q=0;q<count;q++)
- {
- arr2[q]=arr2[q]+inc; //incrementing by given number
- }
- String arr3[]=new String[count];
- for(int r=0;r<count;r++)
- {
- arr3[r]=String.valueOf(arr2[r]); //converting to string
- }
- String arrstring="";
- for(int s=0;s<count;s++)
- {
- arrstring=arrstring+arr3[s];
- }
- int numans=Integer.parseInt(arrstring);
- System.out.println();
- System.out.println("The final number after increamenting all digits is "+numans);
- /*numans++; // incrementing to confirm
- System.out.println(numans); */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement