Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab4;
- import java.util.Scanner;
- public class FibonacciReverse {
- public static Scanner scanner;
- public static void main(String[] args) {
- scanner = new Scanner(System.in);
- System.out.println("---- In dãy Fibonaccy có giá trị lớn nhất < m ----");
- int f0 = 1, f1 = 2;
- System.out.print("Nhập vào số m: ");
- int m = scanner.nextInt();
- while (m<=f1) {
- System.out.print("Số m nhập vào phải >2, xin hãy nhập lại: ");
- m = scanner.nextInt();
- }
- System.out.printf("%d, %d", f0, f1);
- while(f1+f0<m) {
- f0 = f0 + f1;
- f1 = f0 + f1;
- if(f1<m) {
- System.out.printf(", %d, %d", f0, f1);
- } else {
- System.out.printf(", %d", f0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement