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

Write a method named maxElement which return the largest value in array. Have us

ID: 3656439 • Letter: W

Question

Write a method named maxElement which return the largest value in array. Have user input 6 numbers. How do I correct the error in line 15-23 stating class interface, or enum expected. import java.util.Scanner; import java.io.*; public class maxElement { public static int largest_in_array(int[] a, int n) { if (n == 1) return 0; else return Math.max(a[n-1], largest_in_array(a,n-1)); } } public static void main(String[] args) { System.out.println("Amount of numbers to be processed: "); Scanner sc = new Scanner(System.in); int theLargest; int x = sc.nextInt(); int[] collection = new int [x]; for (int i = 0; i < collection.length; i ++) { System.out.println("Please enter 6 numbers: "); collection[i] = sc.nextInt(); } System.out.println(); System.out.println("The largest number in your collection is: "); for (int i = 0; i < collection.length; i++) System.out.println(theLargest); } }

Explanation / Answer

//save the program as maxElement.java import java.util.Scanner; import java.io.*; public class maxElement { public static int largest_in_array(int[] a, int n) { if (n == 1) return 0; else return Math.max(a[n-1], largest_in_array(a,n-1)); } public static void main(String[] args) { int[] collection = new int [6]; Scanner sc = new Scanner(System.in); System.out.println("Please enter 6 numbers: "); for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote