| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:请各位帮忙修改一下~~
只看楼主 加入收藏
shixian987
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2007-10-31
收藏
 问题点数:0 回复次数:0 
请各位帮忙修改一下~~
[题目:
  编写一个输入人员信息并存储到内存的程序,输入部分可参考InputFromConsole类,人员信息包括name, sex, age.并且依据age对人员列表重新升序排序。]
_______________________________________________________
下面这个是我自己写的,程序能够正常运行,但执行后,在输入第一个名字的时候就出错了,还请各位帮忙修改一下,是什么地方的问题,谢谢咯~~~~
______________________________________________________

import java.util.Scanner;

public class PersonMessage {
    String[] Name= null;
    String[] Sex = null;
    int[]    Age = null;
        public void InputFormConsole(){                   //录入信息
           for(int i=0; ; i++){
            System.out.print("请输入名字:");
            Scanner scname= new Scanner(System.in);
            String name = scname.next();
            Name[i] = name;
            
            System.out.print("请输入性别:");
            Scanner scsex= new Scanner(System.in);
            String sex = scsex.next();
            Sex[i] = sex;
            
            System.out.print("请输入年龄:");
            Scanner scage = new Scanner(System.in);
            int age = scage.nextInt();
            Age[i] = age;
            
            System.out.print("是否继续录入:(Y/N)");
            Scanner scInput = new Scanner(System.in);
            String Input = scInput.next();
            
              if (Input.equals("Y")){                     //判断是否继续录入信息
                  PersonMessage r = new PersonMessage();
                  r.InputFormConsole();                  //继续录入信息
              }else {
                  PersonMessage r1 = new PersonMessage();
                  r1.OrderAge();                          //转到age排序
                  }//
            
           }
                       
         }
        
       public void OrderAge(){        
           String NameTemp,SexTemp;
        int AgeTemp;                             //年龄升序排列
           for(int i=0; i<Age.length; i++){
               for(int j=i ;j<Age.length-1; j++){     //排序
                   if(Age[j+1] > Age[j]){
                       AgeTemp = Age[j+1];
                       Age[j+1] = Age[j];
                       Age[j] = AgeTemp;
                       
                       NameTemp = Name[j+1];
                       Name[j+1] = Name[j];
                       Name[j] = NameTemp;
                       
                       SexTemp = Sex[j+1];
                       Sex[j+1] = Sex[j];
                       Sex[j] = SexTemp;
                   }
               }
           }
           
           for(int k=Age.length ;k >= 0 ; k-- ){
               System.out.println("姓名:"+Name[k]+",性别:"+Sex[k]+",年龄:"+Age[k]);
           }
       }
    /**
     * @param args
     */
    public static void main(String[] args) {
       PersonMessage Person =new PersonMessage();
              Person.InputFormConsole();
              
        

        
    }

}
搜索更多相关主题的帖子: null public import 
2008-05-09 13:28
快速回复:请各位帮忙修改一下~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016978 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved