+ 2

Explain this logic of java code

https://code.sololearn.com/cLiY22jJPVBQ/?ref=app Anyone here please see this while loop code of java and help me by commenting the logic of this code how it is working. I am very poor at these kind of codes also tell me how can I improve my self in these types of codes and logic.

1st Aug 2018, 2:20 PM
Robin
Robin - avatar
1 Antwort
+ 5
public class Program { public static void main(String[] args) { int x = 1; int triangularNum = 1; while (x <= 10){ System.out.println(triangularNum); // prints 1 x++; //increase x by 1 // so x would be 1 2 3 4 5 6 7 8 9 10 triangularNum = triangularNum + x; //add x with triangularNum //2+1=3 //3+3=6 //6+4=10 //10+5=15 //so on } } }
1st Aug 2018, 2:48 PM
Daljeet Singh
Daljeet Singh - avatar