For this program, use the program, **************\"ECLIPSE-NEON\"************* P
ID: 3784576 • Letter: F
Question
For this program, use the program,**************"ECLIPSE-NEON"*************
Programming Assignment #1
*****I HAVE POSTED THIS PROBLEM TWICE AND GOT LOUSY RESPONSES. I RAN BOTH PROBLEMS AND IT CRASHED MY PROGRAM. PLEASE RUN THE CODE BEFORE SUBMITTING RESPONSE!!!***** FOR HELP, FIND THE TRIES ON THE BOTTOM OF THIS POST.
The assignment is to create a Java program that manipulates an array.
Step 1:
In the main method, have the user input the size of an array. Create an integer array of that size. Then call the methods outlined in the following steps.
Step 2:
Create a method with signature: public static void initArray( int [] values ) that initializes the integer array with random values between 1 and 10.
Step 3:
Create a method with signature: public static void printArray( int [] values ) that prints the array.
Step 4:
Create a method with signature: public static void squareArray( int [] values ) that prints the array with all values squared, but does NOT change the array.
Step 5:
Create a method with signature: public static void reverseArray( int [] values ) reverses the values of the array. The values of the array should be changed...
Step 6:
Create a method with signature: public static void transposeArray( int [] values ) switches each pair of the array. The values of the array should be changed.
Note: Print the array after each step... (See sample I/O)
Sample INPUT/OUTPUT:
Enter size of array: 6
Values in array are:
1 2 3 4 5 6
Values in array when squared are:
1 4 9 16 25 36
Values in array when reversed are:
6 5 4 3 2 1
Values in array when transposed are:
5 6 3 4 1 2
********AGAIN, PLEASE RUN PROGRAM ON "ECLIPSE NEON" BEFORE SUBMITTING ANSWER***********
a Van LA Public Cass Searc Ca Y Public static void Arras R double C3 mums 1,2,, ,,s, 33 stem Square hums) Print Revenge public void f oint peverseExplanation / Answer
import java.util.*;
public class Array{
public static void main(String []args){
int size;
System.out.println("Enter size of array: ");
Scanner sc = new Scanner(System.in);
size = sc.nextInt();
int [] array = new int[size] ;
initArray(array);
}
public static void initArray( int [] values ){
for(int i=0; i<values.length; i++)
{
Random rand = new Random();
values[i] = rand.nextInt(10) + 1;
}
printArray(values);
}
public static void printArray( int [] values ){
System.out.println("Values in array are: ");
for(int i=0; i<values.length; i++)
System.out.print(values[i] +" ");
System.out.println(" ");
squareArray(values);
reverseArray(values);
}
public static void squareArray( int [] values ){
System.out.println("Values in array when squared are:");
for(int i=0; i<values.length; i++)
System.out.print(values[i] * values[i] +" ");
System.out.println(" ");
}
public static void reverseArray( int [] values ){
int temp;
System.out.println("Values in array when reversed are:");
for(int j=0, i = values.length-1; i>j; j++, i--)
{
temp = values[i];
values[i] = values[j];
values[j] = temp;
}
for(int i=0; i<values.length; i++)
System.out.print(values[i] +" ");
System.out.println(" ");
transposeArray(values);
}
public static void transposeArray( int [] values ){
int temp, i;
System.out.println("Values in array when transposed are:");
for(i=0; i<values.length; i+=2)
{
temp = values[i];
values[i] = values[i+1];
values[i+1] = temp;
}
for(i = 0; i<values.length; i++)
System.out.print(values[i] +" ");
System.out.println(" ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.