import java.io.*;
public class T1
{
 public static void main(String[] args) throws IOException
 {
  short num;
  InputStreamReader a=new InputStreamReader (System.in);
  BufferedReader b=new BufferedReader (a);
  System.out.pritln("请输入成绩: "+"分");
  String c=b.readLine();
  num=Float.parseFloat(c);
  if (num>=90)
  System.out.println("优秀");
  if (num>=80)
  System.out.println("一般");
  if (num>=70)
  System.out.println("良好");
  if (num>=60)
  System.out.println("合格");
  else System.out.println("不合格"); 
 }
}
上面一个小程序里,在CMD上运行后输入一个数据后判断成绩了,怎么样弄可以在输入第二个数据的时候不用再运行一次java t1来进行判断成绩?java

解决方案 »

  1.   

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;public class Test1 {
    public static void main(String[] args) throws IOException {
    float num;
    InputStreamReader a = new InputStreamReader(System.in);
    BufferedReader b = new BufferedReader(a);
    System.out.println("请输入成绩: " + "分");
    String c = b.readLine();
    num = Float.parseFloat(c);
    if (num >= 90)
    System.out.println("优秀");
    else if (num >= 80)
    System.out.println("一般");
    else if (num >= 70)
    System.out.println("良好");
    else if (num >= 60)
    System.out.println("合格");
    else
    System.out.println("不合格");
    }
    }
      

  2.   

    if(){
    } else if(){
    }
    当if()成立时,就不进入else if()了;当不成立时,进入else if()块。
      

  3.   

    package test2;import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;public class A {
    private static void inner() throws Exception {
    short num;
    InputStreamReader a = new InputStreamReader(System.in);
    BufferedReader b = new BufferedReader(a);
    System.out.println("请输入成绩: " + "分");
    String c = b.readLine();
    if (c.equals("exit"))
    System.exit(0);
    else{
    num = Short.parseShort(c);
    if (num >= 90)
    System.out.println("优秀");
    if (num >= 80)
    System.out.println("一般");
    if (num >= 70)
    System.out.println("良好");
    if (num >= 60)
    System.out.println("合格");
    else
    System.out.println("不合格");
    }
    inner();
    } public static void main(String[] args) throws Exception {
    inner();
    }
    }
      

  4.   

    我的意思是怎么写代码能够在CMD上敲的时候不用重复去运行T1,就比如上面的代码,编译后在CMD上运行,第一次输入了99,然后显示优秀,我想再敲个100进去能够显示出来优秀,而不是需要再敲 T1 Java
      

  5.   

    在  String c=b.readLine();后面加个循环
    while(!c.equals("end")){
    ...
    }
      

  6.   

    错了  最外面套个while(true){if(!c.equals("end"))
    return;
    }
      

  7.   

    大哥,你这是控制台程序
    这个 InputStreamReader a=new InputStreamReader (System.in);回车了就没了!!!做个网页版的,不行吗?
      

  8.   

    System.out.println("请输入你的成绩:");
    Scanner scan = new Scanner(System.in);
    int score = scan.nextInt();
    if(score >=90){
    System.out.println("Very good");
    }else{
    System.out.println("go ahead");
    }
    System.out.println("**********just  demo ********");
      

  9.   

    请输入成绩: 分
    50
    不合格
    请输入成绩: 分
    60
    合格
    请输入成绩: 分
    70
    良好
    合格
    请输入成绩: 分
    80
    一般
    良好
    合格
    请输入成绩: 分
    exit
      

  10.   

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    public class A {
        private static void inner() throws Exception {
            short num;
            InputStreamReader a = new InputStreamReader(System.in);
            BufferedReader b = new BufferedReader(a);
            System.out.println("请输入成绩: " + "分");
            String c = b.readLine();
       // exit 跳出循环否则,不断读取输入;跳出执行system.exit(0),结束。
    while(!c.equals("exit")) {
    num = Short.parseShort(c);
    if (num >= 90)
    System.out.println("优秀");
    else if (num >= 80)
    System.out.println("一般");
    else if (num >= 70)
    System.out.println("良好");
    else if (num >= 60)
    System.out.println("合格");
    else
    System.out.println("不合格");
    c = b.readLine();
    }
    System.exit(0);
        }
     
        public static void main(String[] args) throws Exception {
            inner();
        }
    }这个程序没有很强的容错性,输入长int或者其他字母无法处理
      

  11.   

    import java.io.*;
    public class T2
    {
    private static void inner() throws Exception
    {
    short num;
    InputStreamReader a=new InputStreamReader(System.in);
    BufferedReader b=new BufferedReader(a);
    System.out.println("请输入成绩:"+"分");
    String c=b.readLine();
    while(!c.equals("exit"));
    {
    num=Short.parseShort(c);
    if (num>=90)
     System.out.println("优秀");
    else if (num>=80)
     System.out.println("一般");
    else if (num>=70)
     System.out.println("良好");
    else if (num>=60)
     System.out.println("合格");
    else 
     System.out.println("不合格");
    c=b.readLine();
    }
    System.exit(0);
    }
    public static void main(String[] args) throws Exception
    {
    inner();
    }
    }我对着来敲了一遍怎么什么都没的
      

  12.   

    //我敲了17楼的方法发现可以,就是我想要的方法,因为老师现在还没有教.想先学着,我学着17楼的方法敲了另外一个问题,但是总是出错.,模仿不行
    //求行李问题,如果行李小于20kg不用钱,超过20kg就1.2元1kg
    import java.io.*;
    public class T2
    {
    public static void inner() throws Exception
    {
    double w,fee;
    InputStreamReader a=new InputStreamReader(System.in);
    BufferedReader b=new BufferedReader(a);
    System.out.println("请输入行李重量");
    w=Double.parseDouble(b.readLine());
    while(!b.equals("exit"));
     {
       if(w>20)
          fee=1.2*(w-20);
       else 
          fee=0;
      System.out.println(""+w+"Kg行李需要交纳: "+fee+"元");   
    }
    System.exit(0);
    }
    public static void main(String[] args) throws Exception
    {
     inner();
    }
    }这个结果和上面的结果一样,都是在命令指示符上敲了,输入数据后就不能动了
      

  13.   

    while循环的问题,while会执行 大括号里的语句;while(){ }之间不能加分号 ,否则执行空语句,陷入死循环 ...
    死循环:
    while(!b.equals("exit"));   //执行空语句   ;
    { int a = 3;}  //这句不会执行正确如下 :
    while(!b.equals("exit")) 
    { int a = 3;}
      

  14.   

    用do while 循环   或 y用switch case 
      

  15.   

    请笑纳~~~
    /**
     * 
     * @param input
     *            输入的成绩
     */
    private static void showResult(String input) {
    Float num;
    num = Float.parseFloat(input);
    if (num >= 90)
    System.out.println("优秀");
    else if (num >= 80)
    System.out.println("一般");
    else if (num >= 70)
    System.out.println("良好");
    else if (num >= 60)
    System.out.println("合格");
    else
    System.out.println("不合格");
    } public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (true) {
    System.out.println("请输入成绩:  分. [ Q = 退出 ]");
    try {
    String input = scanner.nextLine();
    if (input.trim().length() > 0) {
    if ("Q".equalsIgnoreCase(input)) {
    break;
    }
    // 打印结果
    showResult(input);
    } } catch (Exception e) {
    System.out.println("输入不正确 " + e.toString());
    }
    }
    scanner.close();
    }