for(int i=1;i<=n;n++)
                 ^^^^^i++

解决方案 »

  1.   

    String str = br.readLine();
    while (str != "") {
    n = Integer.parseInt(str)
      

  2.   

    后边还要用n值,改成str后就后边就有问题了
      

  3.   

    while(n!="")
    你这个n是int的怎么可以和""比较,""是String的.
      

  4.   

    String str = br.readLine();
    while (str != "") {
    n = Integer.parseInt(str)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
    这里的n不是让你使用的吗???
      

  5.   

    String str = br.readLine();
    while (str != "") {
    n = Integer.parseInt(str)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
    这里的n不是让你使用的吗???
      

  6.   

    n = Integer.parseInt(str);
    将这个写在while上面
      

  7.   

    1. you have a double-nested-while-loop, but you only have one variable "n". within the inner while loop, you change the value of n, and after it exits, the outer while loop will check the same n. this causes a lot of confusion. try not to do such thing like this. make two variables, inner n and outer n.
    2. do not parse a string to integer then check. read again out the condition of your outer loop. what does n!="" mean? I assume you expect the user not to enter anything to indicating the end of the program. in such case, br.readline() returns an empty String "" which cannot be parsed as integer. parsing exception will be thrown. The solution is to have a String hold value from br.readline() and check the String emptiness in while condition. then inside the while loop, the first thing to do is to parse to outerN.
    3. there's a logic problem here: while(n!=0||n<100) this always stays true, isn't it?
    4. reading your second class, feeling the logic is fuzzy. why do you have inheritance there?  keep in mind that object oriented programming is not functional programming; however, objects in oop are organized and catagorized based on their functionalities.
      

  8.   

    对不起,我不能对你的代码只修改部份还能实现你的功能,现在修改如下:
    希望对你有用.
    对了,你还有一个自相矛盾的地方.可能会造成死循环."while(n!=0||n<100);"当输入N为0时,N!=0继续循环请问如何退出呢?    
    import java.io.*;
    class jisuan {
    public static void main(String[] args)
       throws IOException
    {
    int n;
    System.out.print("请输入1-100之间的整数:");
    while(true){
    int sum=0;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    try{

    n=Integer.parseInt(br.readLine());
    }catch (NumberFormatException e){System.out.println("you don't input the number,the progamme exited.");
    break ;
    }
    if (n==0) break;
    if(n<100){

    //n=Integer.parseInt(br.readLine());
    System.out.println("您输入的是"+n);
    for(int i=1;i<=n;i++)
    sum+=i;
    System.out.println("sum="+sum);
    System.out.println("输入0结束!");
       
    }
    else
    System.out.println("请输入1-100之间的整数:");
    }

       System.out.println("EXITED...."); }
    }
      

  9.   

    int n应该给个初始直呀,
    while(n!="")不能这样比较呀,类型不一样呀
    你应该把编译是的错误提示说出来,负责我们也不知道是什么运行错副呀,有不能试
      

  10.   

    正确的应该是这样的:
    import java.io.*;
    class file {
    public static void main(String[] args) throws IOException {
    int n, sum;
    System.out.print("请输入1-100之间的整数:");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    do {n = 0;sum = 0;
    n = Integer.parseInt(br.readLine());
    if (n > 0 && n < 100) {
    System.out.println("您输入的是" + n);
    for (int i = 1; i <= n; i++)
    sum += i;
    System.out.println("sum=" + sum);
    System.out.println("输入0结束!");
    } else if (n != 0)
    System.out.println("请输入1-100之间的整数:");
    } while (n != 0);
    }
    }