JAVA QUESTION. ABOUT ARRAY! plz help Complete the missing parts of the program b
ID: 3568662 • Letter: J
Question
JAVA QUESTION. ABOUT ARRAY! plz help
Complete the missing parts of the program by determining from the method headers what the program is
intended to do.
{
/*-----------------------------------------------------------------------
Method name: main
Description: Creates an integer array, then creates a new array in which
the values of the first are reversed. Display the arrays. Input: None
Output: None
Calls: reverse() and printList()
Returns: None
-------------------------------------------------------------------------
*/
public static _______ _______( String[] args )
{
int[] list1 = { 1,2,3,4,5,6 };
int[] list2 = __________(list1);
__________(list1);
__________(list2);
}
/*-------------------------------------------------------------
Method name: reverse
Description: Returns an array that is the reversal of another
array
Input: an integer array
Output: none
Returns: a new integer array
--------------------------------------------------------------
*/
public static int[] __________(int[] list)
{
int[] newList = new int[__________.length];
for (int i = ___, j= __________.length - 1; i < __________.length; i++, j--)
__________[___] = __________[___];
return newList;
}
/*-------------------------------------------------------------
Method name: printList
Description: Prints the contents of an integer array.
Input: an integer array
Output: display an integer array
Returns: none
--------------------------------------------------------------
*/
public static void __________(int[] list)
{
for (int i = 0; i < _________.length; i++)
{
System.out.print(_________[___]);
if (i < _________.length - 1)
System.out.print(", ");
}
System.out.println();
}
}// end class
Explanation / Answer
{
/*-----------------------------------------------------------------------
Method name: main
Description: Creates an integer array, then creates a new array in which
the values of the first are reversed. Display the arrays. Input: None
Output: None
Calls: reverse() and printList()
Returns: None
-------------------------------------------------------------------------
*/
public static void main( String[] args )
{
int[] list1 = { 1,2,3,4,5,6 };
int[] list2 = reverse(list1);
printList(list1);
printList(list2);
}
/*-------------------------------------------------------------
Method name: reverse
Description: Returns an array that is the reversal of another
array
Input: an integer array
Output: none
Returns: a new integer array
--------------------------------------------------------------
*/
public static int[]reverse(int[] list)
{
int[] newList = new int[list.length];
for (int i = 0, j= newList.length - 1; i <list .length; i++, j--)
newList[j] = list[i];
return newList;
}
/*-------------------------------------------------------------
Method name: printList
Description: Prints the contents of an integer array.
Input: an integer array
Output: display an integer array
Returns: none
--------------------------------------------------------------
*/
public static void printList(int[] list)
{
for (int i = 0; i < list.length; i++)
{
System.out.print(list[i]);
if (i < list.length - 1)
System.out.print(", ");
}
System.out.println();
}
}// end class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.