Computer Science, asked by justauser2, 1 year ago

write a program to input a number and display the new number of the reversing the digits of the original number. the program also displays the absolute difference between original number and the reversed number.

sample input : 194
Sample output : 491
Absolute difference : 297

write the program using either inputstreamreader or scanner classes

Answers

Answered by kir2
28
Hope its helpful!!!!
Attachments:

justauser2: correct r u sure??
kir2: yes...only left one thing .---> int d=0
kir2: int d=0....in variable declaration add it
kir2: then it's correct 100% sure
justauser2: ah tqsm
kir2: wlcm
kir2: ☺☺☺☺☺
Answered by sandilyamahesh03
31

Answer:

example;

if we take a number like 194

then its reversed digits are 491 and its absolute difference is (194-491)=-297 which is 297 avoid the symbols.

Explanation:

import java.util.*;  

class tenth

{

   public static void main()

   {

       Scanner sc=new Scanner(System.in);

       int n,r=0,a,b;

       System.out.println("Enter the number to find its reverse number and absolute difference");

       n=sc.nextInt();

       while(n != 0)

       {

           int d=n%10;

           r =r*10+d;

           n/=10;

           

       }

       a=Math.abs(n-r);

       System.out.println("The reversed number="+r);

       System.out.println("The Absolute difference="+a);

   }

}

Similar questions