using the switch statement in java print the series 2,3,5,8,,,,,,,,,20 times
Answers
Answered by
3
CORRECT QUESTION.
- Write a Java program to display the series - 2, 3, 5, 8, . . . 20 terms.
THE CODE.
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
Hindi,
28 days ago
Physics,
28 days ago
Social Sciences,
1 month ago
English,
1 month ago
Math,
9 months ago
World Languages,
9 months ago