+ 2
1,3,6,11,20,37,70,135......n terms
java for loop program
5 Respuestas
+ 3
do u need a help with algorithm?
+ 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+",");
}
}
+ 2
Thanks!
+ 2
Thanks!
+ 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;
}
}
}