姓名  学号  分数  性别
张三  101    70   男
李四  102    90   女
王武  103    80   男
我想把学号当成key,分数作为一个排序(如升序)的条件,把性别为‘男’的屏幕输出,应该怎么做??

解决方案 »

  1.   

    又要按分数进行排序,又要把学号当key?
      

  2.   

    如果楼住想只用java不用数据库可以这样做:
    class PersonInfo{
    private String name;
    private int key;
    private int scot;
    private String sex;

    public void setName(String name){
    this.name = name;
    }

    public void setKey(int key){
    this.key = key;
    }

    public void setScot(int scot){
    this.scot = scot;
    }

    public void setSex(String sex){
    this.sex = sex;
    }

    public String getName(){
    return this.name;
    }

    public int getKey(){
    return this.key;
    }

    public int getScot(){
    return this.scot;
    }

    public String getSex(){
    return this.sex;
    }

    public PersonInfo(String name,int key,int scot,String sex){
    this.name = name;
    this.key = key;
    this.scot = scot;
    this.sex = sex;
    }

    public PersonInfo(){}
    }class CompareInfo{
    private PersonInfo[] pi;

    public CompareInfo(PersonInfo[] pi){
    this.pi = pi;
    }

    public PersonInfo[] comparePerson(){
    for(int i = 0;i<pi.length;i++){
    for(int j = i+1;j<pi.length;j++){
    if(pi[i].getScot()>pi[j].getScot()){
    PersonInfo p = new PersonInfo();
    p = pi[i];
    pi[i] = pi[j];
    pi[j] = p;
    }
    }
    }
    return pi;
    }
    }class Person{
    public static void main(String[] args){

    PersonInfo pOne = new PersonInfo("张三",101,70,"男");
    PersonInfo pTwo = new PersonInfo("李四",102,90,"女");
    PersonInfo pThree = new PersonInfo("王武",103,80,"男");

    PersonInfo[] pi = {pOne,pTwo,pThree};
    CompareInfo comInfo = new CompareInfo(pi);

    pi = comInfo.comparePerson();

    for(int i = 0;i<pi.length;i++){
    if(pi[i].getSex().equals("男")){
    System.out.println(pi[i].getName()+","+
    pi[i].getKey()+","+pi[i].getScot()+","+pi[i].getSex());
    }
    }
    }
    }
      

  3.   

    select * from *** where 性别 = "男" order by 分数 ;