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

Write a Java class FirstEl with a method fel that takes atwo-dimensional integer

ID: 3618964 • Letter: W

Question

Write a Java class FirstEl with a method fel that takes atwo-dimensional integer array arr and returns a one-dimensional array firs. The array firsconsists of the first elements of rows in array arr; that is, the i-th entry of firs is(i,0)-th entry of arr (here i is any integer from i=0 to i=arr.length - 1). The method shouldbe applied to array fff = {{2,3}, {5,3,1}, {4,1,5,6}, {1,3}}. Hint: The resulting array will be firs = {2, 5, 4, 1}.

PLEASE GIVE AN EXPLANATION OF EACH OF THE LINES ANDBRACKETS THANKS
Answer: The class might be as follows: public class FirstEl{ public static void main(String[] args){ int[][] fff={{2,3}, {5,3,1},{3,1,5,6},{1,3}}; int[] firs=fel(fff); for (int i=0; i<firs.length; i++) System.out.print(firs[i]+" "); System.out.println(); } public static int[] fel(int[][] arr){ int[] tti=new int[arr.length]; for (int i=0; i<arr.length;i++) tti[i]=arr[i][0]; return tti; } } Write a Java class FirstEl with a method fel that takes atwo-dimensional integer array arr and returns a one-dimensional array firs. The array firsconsists of the first elements of rows in array arr; that is, the i-th entry of firs is(i,0)-th entry of arr (here i is any integer from i=0 to i=arr.length - 1). The method shouldbe applied to array fff = {{2,3}, {5,3,1}, {4,1,5,6}, {1,3}}. Hint: The resulting array will be firs = {2, 5, 4, 1}.

PLEASE GIVE AN EXPLANATION OF EACH OF THE LINES ANDBRACKETS THANKS
Answer: The class might be as follows: public class FirstEl{ public static void main(String[] args){ int[][] fff={{2,3}, {5,3,1},{3,1,5,6},{1,3}}; int[] firs=fel(fff); for (int i=0; i<firs.length; i++) System.out.print(firs[i]+" "); System.out.println(); } public static int[] fel(int[][] arr){ int[] tti=new int[arr.length]; for (int i=0; i<arr.length;i++) tti[i]=arr[i][0]; return tti; } }

Explanation / Answer

public class FirstEl{ public static void main(String[] args){ int[][] fff={{2,3}, {5,3,1},{3,1,5,6},{1,3}}; int[] firs=fel(fff); for (int i=0; i<firs.length; i++) System.out.print(firs[i]+" "); System.out.println(); } public static int[] fel(int[][] arr){ int[] tti=new int[arr.length]; for (int i=0; i<arr.length;i++) tti[i]=arr[i][0]; return tti; } }
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