请帮帮忙 我是初学者

wb792973367 2008-05-19 11:28:41
如何将此程序的输出改成按倒序排列???
import java.util.*;
public class Daoxu {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] score=new int[5];
Scanner input=new Scanner(System.in);
System.out.println("请输入成绩");
for(int i=0;i<5;i++){
score[i]=input.nextInt();
}
Arrays.sort(score);
System.out.println("学员成绩按升序排列");
for(int index=0;index<score.length;index++){
System.out.println(score[index]);
}
}

}
...全文
88 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sunksubmarine 2008-05-23
  • 打赏
  • 举报
回复
for(int i=score.length-1 ; i>=0 ; i--){
System.out.println(i+":"+score[i]);
}
wb792973367 2008-05-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jdlsfl 的回复:]
Java code public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] score = new int[5];
Scanner input = new Scanner(System.in);
System.out.println("请输入成绩");
for (int i = 0; i < 5; i++)
{
score[i] = input.nextInt();
}
Arrays.sort(score);
System.out.println("学员成绩按…
[/Quote]谢谢
水瘦山寒 2008-05-19
  • 打赏
  • 举报
回复
不知道有没有什么系统方法,不过可以这样实现

把按升序排列好的数组遍历出来,从最后一个,重新装到新的数组里面
int[] newscore=new int[5];
for(int index=score.length;index > 0 ;index--){
newscore[index]=score[index];
}
老紫竹 2008-05-19
  • 打赏
  • 举报
回复
反向输出就可以了,从最后一个开始。

请参考1楼的代码
jdlsfl 2008-05-19
  • 打赏
  • 举报
回复
    public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] score = new int[5];
Scanner input = new Scanner(System.in);
System.out.println("请输入成绩");
for (int i = 0; i < 5; i++)
{
score[i] = input.nextInt();
}
Arrays.sort(score);
System.out.println("学员成绩按升序排列");
for (int index = 0; index < score.length; index++)
{
System.out.println(score[index]);
}
System.out.println("学员成绩按jiang序排列");
for (int index =score.length-1 ; index >=0; index--)
{
System.out.println(score[index]);
}
}
skyqiang 2008-05-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jdlsfl 的回复:]
Java code public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] score = new int[5];
Scanner input = new Scanner(System.in);
System.out.println("请输入成绩");
for (int i = 0; i < 5; i++)
{
score[i] = input.nextInt();
}
Arrays.sort(score);
System.out.println("学员成绩按…
[/Quote]

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧