Question: /** This class has a main method that prints out an integer array in various ways Difficulty: Easy */ public class ArrayPrinter { public static

/**
This class has a main method that prints out an integer array in various ways

Difficulty: Easy
*/

public class ArrayPrinter
{
public static void main(String[] args)
{
int[] data = {2, 34, 57, 31, 5, 79, 88, 62, 98, 53, 42};


//-----------Start below here. To do: approximate lines of code = 2
// Write a loop to print out even indices (NOTE: not the elements) of array data
    // use System.out.print, not System.out.println so the numbers are printed on one line




//-----------------End here. Reminder: no changes outside the todo regions.
System.out.println();
System.out.println("EXPECTED:") ;
System.out.println("0 2 4 6 8 10");


//-----------Start below here. To do: approximate lines of code = 3
// Write a loop to print out even integer elements stored in array data
    // Hint: use the modulus operator % to determine if an integer element is even







//-----------------End here. Reminder: no changes outside the todo regions.
System.out.println();
System.out.println("EXPECTED:") ;
System.out.println("2 34 88 62 98 42");

//-----------Start below here. To do: approximate lines of code = 2
// Print out the elements in reverse order
    //Hint: use a for loop but start at the end of the array and count down




//-----------------End here. Reminder: no changes outside the todo regions.
System.out.println();
System.out.println("EXPECTED:") ;
System.out.println("42 53 98 62 88 79 5 31 57 34 2");

//-----------Start below here. To do: approximate lines of code = 1
// Print out only the first and last element

//-----------------End here. Reminder: no changes outside the todo regions.
System.out.println("EXPECTED:") ;
System.out.println("2 42");
}
}

 Include screenshots too for formatting.

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

for int j 0 j datalength j2 systemoutprintdataj for int j 0 j dat... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!