Question: Question in regards to my Intro to Java Programing. There are a few issues with the following code. Report the lines that have issues and
Question in regards to my Intro to Java Programing.
There are a few issues with the following code. Report the lines that have issues and how they may be corrected so the code will work.
1.
2. //Begin Main Method
3. public static void main(String[] args) {
4. printMax(1, 2, 2, 1, 4);
5. printMax(new double[]{1, 2, 3, 78});
6. printMax(new int[]{2, 5, 9, 23});
7. } //End Main Method
8.
9. public static void printMax(double... numbers) {
10. if (numbers.length == 0) {
11. System.out.println("This is an empty set.");
12. return;
13. }
14.
15. double result = numbers[0];
16.
17. for (int i = 0; i <= numbers.length; i++) {
18. if (numbers[i] > result) {
19. result = numbers[i];
20. }
21. }
22. System.out.printf("Max is: %f ", result);
23. }//End printMax method Previous Next
24.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
