user2967495
user2967495

Reputation: 1

Java compile error in getting Triangular numbers sequence

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+"");
        }
    }
}

Upvotes: 0

Views: 181

Answers (2)

Juned Ahsan
Juned Ahsan

Reputation: 68715

You are missing && in between two comparisons:

Count1>=1  Count2=0

should be

Count1>=1  && Count2=0

Also you are using single = which is for assignment. Use == for comparison. So finally this should be your condition:

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

Note: You may have to replace && with some other operator(||, != etc). I just used it for example.

Upvotes: 1

Aniket Inge
Aniket Inge

Reputation: 25725

while(Count1>=1 Count2 = 0) <- here is the error.. makes no sense absolutely.

What are you trying to do?

Upvotes: 0

Related Questions