Zoom
1 import java.util.Scanner;
2
3 class Fibonacci {
4
public static void main(String args) {
5
int n;
6
System.out.print("Enter the number of first digits in "the fibonacci sequence you want to output: ");
7
8
try (Scanner scanner Scanner(System.in)) {
9
n scanner.nextInt();
10
}
11
int n1 0; n2= 1;
12
if (n == 1) {
13
System.out.print(n1);
14
} else if (n == 2) {
15
System.out.print(n1+" "+ n2);
16
} else {
17
System.out.print(n1 + + n2);
18
int tempNthTerm;
19
20
21
22
23
for (int i= 3; i <= n 1; i++) {
tempNthTerm = n1n2;
System.out.print("" + tempNthTerm);
n2 tempNthTerm;
n1= n2;
24
25 26 } }
}
27 }
+ 100%
Page 11
Close