Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** 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

Step: 1

for int j 0 j datalength j2 systemoutprintdataj for int j 0 j dat... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Economics Of The Environment

Authors: Peter Berck, Gloria Helfand

1st Edition

978-0321321664, 0321321669

More Books

Students also viewed these Programming questions

Question

6. How does an epigenetic change differ from a mutationpg78

Answered: 1 week ago