SWT301_-_SU_2024_-_PE1_2328.webp
H

SWT301_-_SU_2024_-_PE1_2328.webp

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
Chưa có bình luận nào.

Thông tin

Category
SWT301
Thêm bởi
Hạnh Dung1
Ngày thêm
Lượt xem
4,195
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Image metadata

Filename
SWT301_-_SU_2024_-_PE1_2328.webp
File size
153.9 KB
Dimensions
1920px x 803px

Share this media

Back
Bên trên Bottom