我需要编写一个程序,使用气泡排序方法和主要功能,要求用户输入他们的数组。之后,程序按升序对数组进行排序。我的程序现在要求用户输入,但是一旦发生这种情况,程序将无法编译,我被卡住了。下面的代码:按升序排列的气泡 - 程序无法编译
import java.util.Scanner;
public class IntSorter{
public static int bubbleSort(int[] a){
boolean needNextPass =true;
for(int i=1; i<a.length && needNextPass; i++){
needNextPass = false;
for(int j=0; j<a.length - i; j++){
if(a[j]> a[j+1]){
int temp = a[j];
a[j]=a[j+1];
a[j+1] = temp;
needNextPass = true;
}
}
}
for(int i=0; i<a.length; i++){
System.out.print(a[j] + " ");
}
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter size of array: ");
int N = input.nextInt();
int[] x = new int[N];
System.out.print("Enter " +N +"numbers of your array: ");
for(int i= 0; i<N; i++){
x[i] = input.nextInt()
}
IntSorter access = new IntSorter();
System.out.print("Your sorted array is: ");
access.IntSorter(x);}
}
'但是一旦发生这种情况,程序将不会编译': - 您的程序在您已经运行后不能编译? –
你收到什么信息? – raam86