+ 2

1,3,6,11,20,37,70,135......n terms

java for loop program

16th Sep 2018, 6:43 PM
Sarah
Sarah - avatar
5 Answers
+ 3
do u need a help with algorithm?
16th Sep 2018, 7:56 PM
patos
patos - avatar
+ 2
Maybe you mean like this? public static void main(String[] args){ char[] arr = {1,3,6,11,20,37,70,135}; for(int a: arr){ System.out.print(a+","); } }
16th Sep 2018, 8:19 PM
JavaBobbo
JavaBobbo - avatar
+ 2
Thanks!
19th Sep 2018, 6:52 PM
Sarah
Sarah - avatar
+ 2
Thanks!
1st Oct 2018, 7:53 PM
Sarah
Sarah - avatar
+ 1
I am a few days late, but... import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int s1 = 1, s2 = 2, s3 = 1; for(int i = 1; i<=n;i++){ System.out.print(s1 + ", "); s1 += s2; s2 += s3; s3 *= 2; } } }
30th Sep 2018, 12:42 PM
Yuvraj Singh
Yuvraj Singh - avatar