Question: Sorted Golf Scores Design a program that asks the user to enter 10 golf scores. The scores should be stored in an Integer array. Sort
Sorted Golf Scores
Design a program that asks the user to enter 10 golf scores. The scores should be stored in an Integer array. Sort the array in ascending order and display its contents.
ASK Pseudocode!!!!!! NOT JAVA CODE!!!
JAVA CODE:(PLEASE transfer to the Pseudocode )
import java.util.Scanner;
public class GolfScores{
static void bubbleSort(int myArray[]){
int n = myArray.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (myArray[j] > myArray[j+1]){
// swap temp and arr[i]
int temp = myArray[j];
myArray[j] = myArray[j+1];
myArray[j+1] = temp;
}
}
// Prints the array
static void display(int myArray[]){
int n = myArray.length;
for (int i=0; i System.out.print(myArray[i] + " "); System.out.println(); } // Driver method to test above public static void main(String args[]){ int score[]= new int[10]; Scanner sc = new Scanner(System.in); System.out.print("Enter 10 golf score: "); for(int i=0; i<10; i++) score[i] = sc.nextInt(); bubbleSort(score); System.out.println("Sorted score"); display(score); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
