Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

P 2 - ArrayEditor [ 1 0 points ] The attached ArrayEditor program initializes the TenNumbers array with ten random integers. Begin by importing the

P2- ArrayEditor [10 points]
The attached ArrayEditor program initializes the TenNumbers array with ten random integers. Begin by importing
the ArrayEditor project to NetBeans. Next, modify the methods in this program so that the program prints four lines
of output, containing:
All elements in the TenNumbers array.
The contents of TenNumbers, after swapping the first and last elements in the array
The contents of T enNumbers, after replacing all even elements with 0.
The largest value in TenNumbers.
The provided seed code has four method declarations:
The getAllElements method receives an input array of integers and returns a String with all the values in
the array.
The swapFirstLast method receives an input array of integers and returns a new array of integers with the
same values as the input array, except the first and last elements being swapped.
The replaceEvensWithZeros method receives an input array of integers and returns a new array of
integers with the same values as the input array, except that all even elements are replaced with 0.
The largestElement method receives an input array of integers and returns the largest value in this array
You will need to use looping statements and method calls.
A screenshot of the execution of your program should look like this:
This in Java using netbeains also pleaze build of the code added
package arrayeditor;
public class ArrayEditor {
static String getAllElements(int[] input){
String output ="";
// Complete this method
return output;
}
static int[] swapFirstLast(int[] input){
int[] output = new int[input.length];
// Complete this method
return output;
}
static int[] replaceEvensWithZeros(int[] input){
int[] output = new int[input.length];
// Complete this method
return output;
}
static int largestElement(int[] input){
int largest = Integer.MIN_VALUE;
// Complete this method
return largest;
}
public static void main(String[] args){
int[] TenNumbers = new int[10];
for (int index =0; index TenNumbers.length; index++){
TenNumbers[index]=(int)(Math.random()*100);
}
System.out.println("All elements: "+ getAllElements(TenNumbers));
System.out.println("After swapping the first and last elements in the array: "+ getAllElements(swapFirstLast(TenNumbers)));
System.out.println("After replacing all even elements with 0: "+ getAllElements(replaceEvensWithZeros(TenNumbers)));
System.out.println("The largest value: "+ largestElement(TenNumbers));
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions