Question: 2. The following program read a three-digits number from user input, reverse it and display the reversed number (No need to deal with exceptions or

image text in transcribed

2. The following program read a three-digits number from user input, reverse it and display the reversed number (No need to deal with exceptions or special cases). Read the codes, design the reverse method to complete the program. (5 marks) import java.util.Scanner; public class DigitReverse { protected int num; public DigitReverse(int num) { if (num999) ( System.exit(); } else { this. num = num; } } I/Write the reverse() method here public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number to reverse (181 - 998): "); try { int num = input.nextInt(); DigitReverse dr = new DigitReverse(num); dr.reverse(); System.out.println("The reversed number is" + dr. num); } catch(Exception ex) { System.out.println(ex.toString()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!