0

How to print serial using while loop-1 4 7 11 16 22 29

6th Aug 2017, 2:24 PM
ketana kasar
ketana kasar - avatar
6 ответов
+ 1
That's the answer to that👇👇 class serial { public static void main(string args[]) { int n=2,s=2; System.out.print("1"); while(n<9) { s=s+n; System.out.print(+s); n=n+1; } } } 👍
8th Aug 2017, 9:35 AM
ketana kasar
ketana kasar - avatar
+ 12
Is the series 2, 4, 7, 11, 16, 22, 29? 1 + (1) = 2 2 + (2) = 4 4 + (3) = 7 7 + (4) = 11 11 + (5) = 16 16 + (6) = 22 22 + (7) = 29
6th Aug 2017, 2:41 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 11
@Krishna - something tells me that is the correct one 😃
6th Aug 2017, 2:42 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 10
are you sure that is the correct series?
6th Aug 2017, 2:35 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 1
here is the code 👇 Scanner sc = new Scanner (System.in); //enter no. of terms u want int n= sc.nextInt (); System.out.println (1 +""); //bcz its not satisfying the sequence int x=3; int y=4; while (n>0) //u said to use while loop { System.out.println (y); y +=x; x++; //as the difference between two consecutive terms is increasing by 1 each time n--; } //working fine , give it a green tick if u like the solution 👆
6th Aug 2017, 3:12 PM
Changed
Changed - avatar
0
yes
6th Aug 2017, 2:40 PM
ketana kasar
ketana kasar - avatar