Question
package prg420week4_analyzeassignment; import java.util.*; // import the java utilities classes which we will need to sort our array public class PRG420Week4_AnalyzeAssignment { public static void
package prg420week4_analyzeassignment;
import java.util.*; // import the java utilities classes which we will need to sort our array
public class PRG420Week4_AnalyzeAssignment {
public static void main(String args[]) {
int[ ] arraynum; // Declare arraynum as an array of integers (int).
arraynum = new int[8]; // Now create space in arraynum for 8 elements of type integeger.
arraynum[0] = 5; // Load some integer values in the array.
arraynum[1] = 10; // In a real-life program, we would probably
arraynum[2] = 15; // get our values from a user or input file.
arraynum[3] = 11; // We are loading values like this so you can focus
arraynum[4] = 1; // on how arrays work.
arraynum[5] = 2;
arraynum[6] = 3;
arraynum[7] = 4;
//////////////////////// Display the elements BEFORE sorting
System.out.println("Here is the order in which array elements were created:");
for (int j=0; j < arraynum.length; j++) {
System.out.println("The value of arraynum[" + j + "] is " + arraynum[j]);
}
Arrays.sort(arraynum); // Send our arraynum array to be sorted in ascending order by the sort() method
int i; // Define the counter for the loop. We can do it this way or inside
// the for loop, as we did in the preceding for loop.
//////////////////////// Display the elements AFTER sorting
System.out.println(" Here is the order of array elements AFTER sorting:"); // The means newline (for formatting)
for (i=0; i < arraynum.length; i++) { // Loop, starting at 0 and adding 1 each time, until counter is less than array length.
System.out.println("The value of arraynum[" + i + "] is " + arraynum[i]); // print the numbers
}
}
}
these are the questions for the program above thank you
If an array had not been chosen to hold the data manipulated in this program, how else (i.e., with what other data types) could it have been represented?
Which approach, using an array or using the alternative you identified in question #1, is shorter/easier?
What is the output of this program?
What would be the result of using a println() statement to display the value of arraynum[8]?
How many values can arraynum contain, and why?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started