Computer Science, asked by ammlan106790, 1 month ago

using the switch statement in java print the series 2,3,5,8,,,,,,,,,20 times​

Answers

Answered by anindyaadhikari13
3

CORRECT QUESTION.

  • Write a Java program to display the series - 2, 3, 5, 8, . . . 20 terms.

THE CO‎‎‎DE.

public class Series{

   public static void main(String s[]){

       for(int i=1,a=2;i<=20;a+=i++)

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

   }

}

LOGIC.

  • First term of this series is 2.
  • Difference between each term goes like - 1, 2, 3, 4, . . . N

See the attachment for output.

Attachments:
Similar questions