So I currently am having, this issue when I run my program it repeats the second display line. ("unsorted line")
I also am having trouble with the alignment when I run the program
What I need this program to do:
Generate 10 random integer numbers between 1 and 100, and place each random number in a different element of a single-dimension array starting with the first number generated.
Locate the largest of the 10 numbers and display its value.
Display the array's contents in the order the numbers are initially inserted. This is called an unsorted list.
Using the bubble sort, now sort the array from smallest integer to the largest. The bubble sort must be in its own method; it cannot be in the main method.
This is what I currently have programmed.. I just need help on adjustments when its ran.
import java.util.Arrays;
public class Chpt7_Project2 {
//Ashley Snyder
public static void main(String[] args) {
//create an array of 10 integers
int[] list = new int[10];
//initialize array of 10 random integers between 0 and 100
for (int i = 0; i < list.length; i++) {
list[i] = (int) (Math.random() * 100 + 1);
}
//Find the maximum of the list of random numbers generated
int maximum = -1;
int minimum = 999;
for (int i = 0; i < list.length; i++) {
if (maximum < list[i])
maximum = list[i];
if (minimum > list[i])
minimum = list[i];
}
//Display the maximum from the randTen array
System.out.println("The largest value is: " + maximum);
//Display the unsorted list of numbers from the randTen array
for (int i = 0; i < list.length; i++) {
System.out.print(list[i] + "The unsorted list is: ");
}
//Display the sorted array numbers
bubbleSort(list);
System.out.println("The sorted list is: " + Arrays.toString(list) + " ");
}
public static void bubbleSort(int[] list) {
//Sort randomly generated integers in randArray from lowest to highest
int temp;
for (int i = list.length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (list[j] > list[j + 1]) {
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}