0
How to print serial using while loop-1 4 7 11 16 22 29
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;
}
}
}
👍
+ 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
+ 11
@Krishna - something tells me that is the correct one 😃
+ 10
are you sure that is the correct series?
+ 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
👆
0
yes