import java.util.Scanner;

public class Arithmetic {


    public static void main(String[] args) {
        System.out.print("规则第n个数=第n-1个数+第n-2个数:");
//        num1 第n-1个数,num2 第n-2个数。
        int num2 = 1, num1 = 1, temp = 0;
        Scanner sc = new Scanner(System.in);
        int num;

        //录入想要查询的第几位数,录入20结束查询。
        do {
            System.out.print("查看第n个数的值:");
            num = sc.nextInt();
//        如果num=1,则结果是1,如果num是2,则结果是1,如果num是3或之后,则结果是num1+num2
            if (num == 1 | num == 2) {
                System.out.println("第" + num + "个数为:1");
            } else if (num == 0) {
                System.out.println("输入无效,重新输入");
            } else if (num > 2) {
                temp = num1;
                num1 = num2 + num1;
                num2 = temp;
                System.out.println("第" + num + "个数为:" + num1);
            }
        } while (num != 20);
        System.out.println("OVER");
        
    }
}


// 九九乘法表
    public static void main(String[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "*" + i + "=" + j * i + "\t");
            }
            System.out.println();
        }
    }

 

posted on 2022-06-22 18:46  jxba  阅读(23)  评论(0编辑  收藏  举报