Computer Science, asked by ladymedeasolon, 1 month ago

Write a class to accept a multi digit no.(max. 8 digits) and do the following:
Print the reverse number.
Print the absolute difference between them.
Print smallest digit.

will report if spam

Answers

Answered by kajalpal1975
1

Answer:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number");

int num = Math.abs(sc.nextInt());

int copy = num;

if (num > 99999999) {

System.out.println("Max 8 digits");

main(null);

}

int rev = 0;

int small = copy % 10;

while (copy > 0) {

int dig = copy % 10;

rev = (rev * 10) + dig;

if (dig < small) {

small = dig;

}

copy /= 10;

}

System.out.println("Reverse no. : " + rev);

int diff = (int) Math.abs(num-rev);

System.out.println("Absolute difference : " + diff);

System.out.println("Smallest digit : " + small);

}

}

Similar questions