用户提问
//写一个整数数组的排序程序
import java.util.Arrays;
import java.util.Scanner;
public class sort {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
int[] number = new int[10];
for(int i = 0; i < 10; i++)
number[i] = scan.nextInt(); //从键盘中输入数组元素
System.out.println(number);
BubbleSort(number);
System.out.println(number);
}
}
/*
* 随机排列数组,使用优先级方式,每个数组元素A[i] 对应一个优先级P[i],
* 然后依据优先级对数组进行排序
*/
class Sort
{
private static void BubbleSort(int[] data)
{
//冒泡排序
for(int i=len-1; i>0; i--)
{
for(int j=0; j
{
if(P[j]>P[j+1])
{
int temp=data[j];
data[j]=data[j+1];
data[j+1]=temp;
temp=P[j];
P[j]=P[j+1];
P[j+1]=temp;
}
}
}
}
}
推荐答案
整体看了再,你类的创建与归属有问题,还有你输出采用的代码错误,我帮你更正了,代码如下:
import java.util.Arrays;
import java.util.Scanner;
public class sort {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
int[] number = new int[10];
System.out.print("请输入10个整数进行比较;\n");
for(int i = 0; i < 10; i++) {
number[i] = scan.nextInt(); //从键盘中输入数组元素
}
BubbleSort(number);
System.out.println("输入的数组从小大排列为:");
for(int a=0;a<10;a++) {
System.out.print(number[a]+"\t");
}
}
private static void BubbleSort(int[] data)
{
//冒泡排序
for(int i=data.length-1; i>0; i--)
{
for(int j=0; j
{
if(data[j]>data[j+1])
{
int temp=data[j];
data[j]=data[j+1];
data[j+1]=temp;
}
}
}
}
}
辅助答案
用户:问水william
2019年06月26日
你把下面这些我复制的你的代码的这些部分全都删掉,包括大括号:
从这→
}
/*
* 随机排列数组,使用优先级方式,每个数组元素A[i] 对应一个优先级P[i],
* 然后依据优先级对数组进行排序
*/
class Sort
{
←到这都删
然后把BubbleSort方法里的第一个for改一下:
for(int i = data.length-1;i>0;i--)
用户:tongxin009
2019年07月24日
两个类名只是大小写不一样不行,换个名字