Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

"Input Array: " "/narray /N" "/narray Setelah Dilakukan Proses Sorting" "/npengurutan Descending" "/Nhasil/N" "/nnilai Terbesar Dari Array: "

The document defines a sort class with a main method that gets user input of an integer array, sorts the array in descending order using a bubble sort algorithm, prints the sorted array and finds the maximum value. It contains methods to get the array from user input, print the array, perform a descending sort using bubble sort, and return the maximum value of the array.

Uploaded by

Chester Phalevi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

"Input Array: " "/narray /N" "/narray Setelah Dilakukan Proses Sorting" "/npengurutan Descending" "/Nhasil/N" "/nnilai Terbesar Dari Array: "

The document defines a sort class with a main method that gets user input of an integer array, sorts the array in descending order using a bubble sort algorithm, prints the sorted array and finds the maximum value. It contains methods to get the array from user input, print the array, perform a descending sort using bubble sort, and return the maximum value of the array.

Uploaded by

Chester Phalevi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

class sort {

public static void main(String[] kelompok7) {


sort run = new sort();
System.out.print("Input array: ");
int array[] = run.getArray();
System.out.println("\nArray \n");
run.showArray(array);
System.out.println("\nArray setelah dilakukan proses sorting");
System.out.println("\nPengurutan Descending");
int sorted[] = run.sortDsc(array);
System.out.println("\nHasil\n");
run.showArray(sorted);
System.out.println("\nNilai terbesar dari array: " + run.getMax(array));
}
int[] getArray() {
int array[];
String arrayStr[] = new java.util.Scanner(System.in).nextLine().split(" ");
array = new int[arrayStr.length];
for (int i = 0; i < array.length; i++) {
array[i] = Integer.parseInt(arrayStr[i]);
}
return array;
}
void showArray(int array[]) {
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
int[] sortDsc(int array[]) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length - 1; j++) {
if (array[j] < array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
System.out.println("\nProses Pengurutan ke- " + (i + 1));
for (int k = 0; k < array.length; k++) {
if (k < array.length)
System.out.print(array[k] + " ");
}
System.out.println();
}
return array;
}
int getMax(int array[]) {
int max = array[0];
for (int i = 0; i < array.length; i++) {
if (array[i] > max)
max = array[i];
}
return max;
}
}

You might also like