Hintfirst write a static method that reverses a three digit


Write a program called Rev.java to solve the following problem.

The program will optionally take a single three digit integer from the command line, e.g. as follows.

$ java Rev 351

If no number is supplied on the command line, then one will be prompted for as follows.

$ java Rev

Enter a three digit number, with the first digit larger than the third.

351

Either way, if the number is not a three digit number with the first digit larger than the third, an error message must be printed to the console and the program terminated.

A typical session will otherwise be as follows. The number regarded as a decimal string is reversed, and the reverse subtracted from the original. You do not have to convert it to a String to achieve this. Details of the sum are displayed as indicated. Similarly, the result of the subtraction has its reverse added to it, and details of that sum are displayed as indicated. Then the program terminates.

Note that numbers should be always be reversed as if they have three digits, so e.g. 99 should be treated as 099 and its reverse will be 990.

$ java Rev 351

Reverse and subtract:

 351

 153 -

 ---

 198

 

Reverse and add:

 198

 891 +

 ---

1089

$

Hint.First write a static method that reverses a three digit number producing a result as described above, and test it directly from the main method. Your static method should have the following signature.

private static int reverse3(int i)

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Hintfirst write a static method that reverses a three digit
Reference No:- TGS01174946

Expected delivery within 24 Hours