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

Problem: Write a main method based on method call given that prints six numbers

ID: 3632893 • Letter: P

Question

Problem:
Write a main method based on method call given that prints six numbers from array list1 in reverse. The Ch. 6_Mod_6 PowerPoint show the animation on the method call.
Solution:
The array list is: 1 2 3 4 5 6 The reverse array list is: 6 5 4 3 2 1

I think i got the reverse code right:

public static int[] reverse(int[] list) {
int[] result = new int[list.length];

for (int i = 0, j = result.length - 1;
i < list.length; i++, j--) {
result[j] = list[i];
}

return result;
}

However, every time i try to create a main method i get compile errors everywhere. if you could respond with the whole source code that'd be great because this adds bonus points to my exam. thankyou!

Explanation / Answer

please rate - thanks

import java.util.*;
public class main
{public static void main(String[] args)
{int num[]={1,2,3,4,5,6};
int i;
System.out.print("The array list is:");
for(i=0;i<num.length;i++)
    System.out.print(num[i]+" ");
num=reverse(num);
System.out.print(" The reverse array list is:");
for(i=0;i<num.length;i++)
    System.out.print(num[i]+" ");
System.out.println();
}
public static int[] reverse(int[] list) {
int[] result = new int[list.length];

for (int i = 0, j = result.length - 1;
i < list.length; i++, j--) {
result[j] = list[i];
}

return result;
}
}

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