当前位置: 代码迷 >> Java相关 >> 初学Java 做个学生信息录入的时候出了问题
  详细解决方案

初学Java 做个学生信息录入的时候出了问题

热度:129   发布时间:2011-12-05 19:31:26.0
初学Java 做个学生信息录入的时候出了问题
package sanj;
import java.util.*;

public class sanj
{
     static String name;
     static int age;
     static float score;
     static String choise;
     static int j=0;
    public static void main(String args[])
    {
        System.out.print("是否输入学生信息?(若输入按任意键继续 ,若不输入按n或N结束)"+"\n");
        Scanner input=new Scanner(System.in);
        Student student[]=new Student[30];
        choise=input.nextLine();
        while(true)
        {
            if(choise.equals("n")||choise.equals("N"))
                break;
        System.out.print("输入学生姓名:\n");
        name=input.nextLine();
        System.out.print("输入学生的年龄:\n");
        age=input.nextInt();
        System.out.print("输入学生的成绩:\n");
        score=input.nextFloat();
        System.out.print("是否输入学生信息?(若输入按任意键继续 ,若不输入按n或N结束)\n");
        student[j]=new Student(name,age,score);
        j++;
        choise=input.nextLine();
        }
        for(int i=0;i<j-1;i++)
            student[i].show();
    }
}


class Student{
    private String name;
    private int age;
    private float score;
    public Student(String name,int age,float score){
        this.name=name;
        this.age=age;
        this.score=score;
    }
    public void show(){
        System.out.print("姓名:"+name+" "+"年龄:"+age+" "+"成绩:"+score+"\n");
    }
}

我本意是当输入n 或者 N就结束循环输出    但是输入玩第一个学生的信息后它就直接让输入第二个学生的信息了    貌似判断语句失效了   不知道是哪里错了
搜索更多相关的解决方案: class  信息  package  public  import  

----------------解决方案--------------------------------------------------------
把 choise=input.nextLine();
这个 放入while循环就OK了。。
----------------解决方案--------------------------------------------------------
  相关解决方案