Computer Science, asked by abhipsit733, 7 months ago

wap in java to print the series ↓
4,5,8,10,16,15,32,20​

Answers

Answered by Oreki
0

import java.util.Scanner;

public class Series {

public static void main(String[ ] args) {

System.out.print("Enter n - ");

int n = new Scanner(System.in).nextInt( );

for (int i = 2, seriesOne = 4, seriesTwo = 5; i <= n; i++) {

if (i % 2 = = 0) {

System.out.print(seriesOne + " ");

seriesOne *= 2;

continue;

}

System.out.print(seriesTwo + " ");

seriesTwo += 5;

}

}

}

Answered by anindyaadhikari13
1

\star\:\:\:\sf\large\underline\blue{Question:-}

Write a program in Java to print the series.

4 5 8 10 16 15 32 20....

\star\:\:\:\sf\large\underline\blue{Code:-}

import java.util.*;

class Series

{

public static void main(String s[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the term of the series: ");

int n=sc.nextInt();

int a=4, b=5, c=0, d=0;

for(int i=1;i<=n;i++)

{

System.out.print(a+" ");

if(c==0)

{

c=1;

d=a;

a=b;

b+=5;

}

else

{

c=0;

d*=2;

a=d;

}

}// end of loop.

} // end of main()

}// end of class.

Similar questions