write a program by using switch case to print the following
1: 0,1,1,2,3,5,8,13,..................n terms
Answers
Program In Java:
import java.io.*;
import java.util.*;
public class Main{
public static void main(String args[]){
System.out.println("Enter n value : ");
Scanner sc = new Scanner(System.in);
int n = 10, t1 = 0, t2 = 1;
n = sc.nextInt();
System.out.println("The fabinocii series up to "+n" terms is ");
for ( int i = 0 ; i < n ; i++ ){
System.out.print(t1+",");
int sum = t1 + t2;
t1 = t2 ;
t2 = sum;
}
}
}
Output:
Enter n value : 10
The fabinocii series up to "+n" terms is
0,1,1,2,3,5,8,13,21,34
Explanation:
- using switch case we cannot print the fabanocci series because the switch case statement is a multi-way decision that tests whether an expression matches one of a number of constant integer values, and branches accordingly.
- if you want to write it using switch case then we have to initialize your local variables in the beginning
- so here question did not mentioned any initialized variables so switch-case cannot be write for fabinocci series
----Hope you got what you wanted ( mark brainliest if you liked my answer )
in future if you have any other questions related to programming languages you can contact me i will explain them to you or answer them in most cases... :)