I want to make a Bubble Sort Program in Java, but I'm feel trouble. I also being confused with static void
and also public static void
. Actually, I want to convert this program from C++ to Java, but the program have an errors.
This is the Java program that I have created :
import java.util.Scanner;
public class BubbleSort{
static Scanner scan = new Scanner(System.in);
int data[] = new int[20];
static int Nilai[] = new int[20];
static void prosesPerpindahan(int data[],int y){
int x;
for(x=0;x<y;x++){
System.out.print(data[x]+" ");
}
}
static void prosesSorting(int data[],int y){
int proses,x,tampung;
for(proses=1;proses<y;proses++){
for(x=0;x<y-proses;x++) {
if(data[x]>data[x+1]){
tampung=data[x];
data[x]=data[x+1];
data[x+1]=tampung;
}
}
System.out.print("Tahap Ke-"+proses+" : ");
prosesPerpindahan(data,y);
}
}
public static void main(String args[]){
Sort tst = new Sort();
int i, N;
System.out.print("Masukkan Banyak Bilangan : ");
N = tst.nextInt();
for(i=0; i<N; i++){
System.out.print("Elemen ke-"+i+" : ");
Nilai[i] = tst.nextInt();
}
prosesSorting(Nilai,N);
System.out.println("Setelah Di Urutkan dengan Bubble Sort : ");
prosesPerpindahan(Nilai,N);
}
}
When I want to compile that program, will appear this notes :
BubbleSort.java:32: error: cannot find symbol
Sort tst = new Sort();
^
symbol: class Sort
location: class BubbleSort
BubbleSort.java:32: error: cannot find symbol
Sort tst = new Sort();
^
symbol: class Sort
location: class BubbleSort
2 errors
Note : Please answer this question if you can!