获取三角数序列时的Java编译错误

时间:2013-11-08 03:43:33

标签: java loops compiler-errors while-loop

import java.util.Scanner;

class TriNumbers {

    public static void main(String args[]) {
        int Count1=1, Count2=0;
        while (Count1>=1  Count2=0) {
            System.out.println(Count2+=Count1+"");
        }
    }
}

2 个答案:

答案 0 :(得分:1)

在两次比较中你缺少&&

Count1>=1  Count2=0

应该是

Count1>=1  && Count2=0

您还使用单=作为作业。使用==进行比较。所以最后这应该是你的条件:

while (Count1>=1  && Count2==0) 

注意:您可能必须将&&替换为其他运算符(||,!= etc)。我只是以它为例。

答案 1 :(得分:0)

while(Count1>=1 Count2 = 0)< - 这是错误..绝对没有意义。

你想做什么?