java输入一个数组怎么排序_java 键盘输入整数,用数组存储,对整数进行排序,排序方法用一个类。。。怎么错了= =。。。?...

用户提问

//写一个整数数组的排序程序

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日

两个类名只是大小写不一样不行,换个名字

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值