Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write the following answer in JAVA (not javascript). Please provide answe

ID: 3861756 • Letter: P

Question

Please write the following answer in JAVA (not javascript). Please provide answer in copyable text. Show input and output. Thanks in advance.

2) Write a static method and test program for a method called digitRange0 that takes an integer n as an argument and returns the largest difference between the individual digits in the number. For example the call digitRange(68437) should return 5 because the largest difference between individual digits is (8-3). You should test whether the number passed to the method is s- 0 and throw an IllegalArgumentException if not. Passing a 1 digit number should return a 0 (zero). You must test these cases: Method Call Value Returned digitRange(0) 4 digitRange(26) 2 digitRange(42) digitRange(888) digit Range 1234 8 digitRange(24680D 7 digitRange(857492) You can use any techniques you want including Strings. (27 pts) To get full credit, you must show the 8 test values defined above.

Explanation / Answer

DigitRangeTest.java


public class DigitRangeTest {

  
   public static void main(String[] args) {
       System.out.println(digitRange(0));
       System.out.println(digitRange(26));
       System.out.println(digitRange(42));
       System.out.println(digitRange(888));
       System.out.println(digitRange(1234));
       System.out.println(digitRange(24680));
       System.out.println(digitRange(857492));
   }
   public static int digitRange(int n){
       int max = 0;
       int min = 9;
       if(n == 0){
           return 0;
       }
       else{
       while( n != 0){
           int r = n % 10;
           if(max < r){
               max = r;
           }
           if(min > r){
               min = r;
           }
           n = n / 10;
       }
       return max-min;
       }
   }

}

Output:

0
4
2
0
3
8
7