PROGRAMMING:Jmu-java-06 exception - 03 throw and throws
###Preface
In C language, the error code is usually returned to indicate whether a function is executed incorrectly. However, sometimes the error return value may be confused with the normal value.
Exceptions are used in Java to indicate the errors that occur during program running. The main purpose of this experiment is to demonstrate the use of exception mechanism instead of error return value.
###Topic content
Write class ` arrayutils`
**Method: * * ` public static double findmax (double [] arr, int begin, int end)`
**Method function: * * used to return the maximum value between the subscripts begin and END-1 (including END-1) in the ARR array.
Note: findmax * * must be declared with the * * throws keyword.
**Method description:**
1. Begin < end is required, otherwise the corresponding exception (` illegalargumentexception ') will be thrown.
2. Begin must not be less than 0, end must not be greater than arr.length, otherwise, an exception will be thrown.
**Note: * * when throwing an exception, you should let the user know the cause of the error.
###Main method:
1. Enter n to create an int array of size n.
2. Input n integers and put them into the array.
3. input several pairs of integers, representing begin and end, and then call the `ArrayUtils.findMax` method. When the input is not an integer type string, exit the input loop.
4. Finally, use the following code to print the identification information
```
try {
System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
} catch (Exception e1) {
}
```
###Input example:
```in
five
1 3 5 6 8
0 5
3 3
3 4
3 2
-1 3
0 6
end
```
###Output example:
```out
eight
java.lang.IllegalArgumentException: begin:3 >= end:3
six
java.lang.IllegalArgumentException: begin:3 >= end:2
java.lang.IllegalArgumentException: begin:-1 < 0
java.lang.IllegalArgumentException: end:6 > arr.length
//Here is the identification information
```
answer:If there is no answer, please comment
In C language, the error code is usually returned to indicate whether a function is executed incorrectly. However, sometimes the error return value may be confused with the normal value.
Exceptions are used in Java to indicate the errors that occur during program running. The main purpose of this experiment is to demonstrate the use of exception mechanism instead of error return value.
###Topic content
Write class ` arrayutils`
**Method: * * ` public static double findmax (double [] arr, int begin, int end)`
**Method function: * * used to return the maximum value between the subscripts begin and END-1 (including END-1) in the ARR array.
Note: findmax * * must be declared with the * * throws keyword.
**Method description:**
1. Begin < end is required, otherwise the corresponding exception (` illegalargumentexception ') will be thrown.
2. Begin must not be less than 0, end must not be greater than arr.length, otherwise, an exception will be thrown.
**Note: * * when throwing an exception, you should let the user know the cause of the error.
###Main method:
1. Enter n to create an int array of size n.
2. Input n integers and put them into the array.
3. input several pairs of integers, representing begin and end, and then call the `ArrayUtils.findMax` method. When the input is not an integer type string, exit the input loop.
4. Finally, use the following code to print the identification information
```
try {
System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
} catch (Exception e1) {
}
```
###Input example:
```in
five
1 3 5 6 8
0 5
3 3
3 4
3 2
-1 3
0 6
end
```
###Output example:
```out
eight
java.lang.IllegalArgumentException: begin:3 >= end:3
six
java.lang.IllegalArgumentException: begin:3 >= end:2
java.lang.IllegalArgumentException: begin:-1 < 0
java.lang.IllegalArgumentException: end:6 > arr.length
//Here is the identification information
```
answer:If there is no answer, please comment