平均成绩、模拟计算器、素数问题、表格、图形、闰年、BMI、水仙花数

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    void demo01(){
        Scanner sc = new Scanner(System.in);
        double sum=0;
        double score=0;

        for (int i=1;i<=5;i++){
            System.out.print("请您输入第"+i+"门的成绩:");
            score=sc.nextInt();
            sum+=score;
        }
        double ave = sum/5;
        System.out.println("同学S1平均分为:"+ave);

    }

    void demo02(){
        System.out.print("请输入一个整数,判断该数是否是质数(素数):");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        boolean flag = true;
        for (int i=2;i<num;i++){
            if(num%i==0){
                flag=false;
                break;
            }
        }
        if (flag){
            System.out.println(num+"是质数");
        }else {
            System.out.println(num+"是合数");
        }

    }

    void demo03(){
        int sum=0;
        for (int i=1;i<=100;i++){
            if(i%3!=0)
                sum+=i;
        }
        System.out.println("sum="+sum);
    }

    void demo04(){
        System.out.println("请输入数字打印表格:");
        Scanner sc  = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i=1;i<=n;i++){
            System.out.print(i+"\t"+i*i+"\t"+i*i*i);
            System.out.println();
        }
    }

    void demo05(){
        //三角形
        System.out.println("请输入打印图形的行数:");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=1;i<=n;i++){
            for (int j=1;j<=i;j++) {
                System.out.print("*");
            }
            System.out.println();
        }

        //金字塔
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n-i;j++){
                System.out.print(" ");
            }
            for (int k=1;k<=2*i-1;k++){
                System.out.print("*");
            }
            System.out.println();
        }

        //一棵树
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n-i;j++){
                System.out.print(" ");
            }
            for (int k=1;k<=2*i-1;k++){
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n-1;j++){
                System.out.print(" ");
            }
            System.out.print("*");
            System.out.println();
        }

        //实心菱形
        for (int i=1;i<=n/2+1;i++){
            for (int j=1;j<=n/2+1-i;j++){
                System.out.print(" ");
            }
            for (int k=1;k<=2*i-1;k++){
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i=1;i<=n/2;i++){
            for (int j=1;j<=i;j++){
                System.out.print(" ");
            }
            for (int k=1;k<=2*(n/2)-(2*i-1);k++){
                System.out.print("*");
            }
            System.out.println();
        }




    }

    void demo06(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请依次输入一个数和一个运算符和另一个数:");
        int a =sc.nextInt();
        String op =sc.next();
        int b =sc.nextInt();
        switch (op){
            case "+":
                System.out.println("a+b="+(a+b));
                break;
            case "-":
                System.out.println("a-b="+(a-b));
                break;
            case "*":
                System.out.println("a*b="+(a*b));
                break;
            case "/":
                System.out.println("a/b="+(a/b));
                break;
            case "%":
                System.out.println("a%b="+(a%b));
                break;
        }
    }
    void demo07(){
        List list= new ArrayList();
        for (int i=100;i<=1000;i++) {
            if (i % 5 == 0 && i % 6 == 0)
            {
                list.add(i);
            }
        }
        System.out.print(list);
    }

    void demo08(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if ( (a % 4 == 0 && a % 100 != 0 )|| (a % 400 == 0)) {
            System.out.println("闰年");
        }
        else {
            System.out.println("不是闰年");
        }

    }

     void demo09(){
        Scanner sc=new Scanner(System.in);
        int n =sc.nextInt();
        int flag = 1;
        double temp = 1;
        double sum = 0;
        for(int i=1;i<=n;i++){
            temp = 1.0/(2*i-1)*flag;
            sum = sum+temp;
            flag = -flag;
        }
        System.out.println(4*sum);
    }

    void demo10(){
        System.out.println("请输入您的体重和身高:");
        Scanner sc =new Scanner(System.in);
        double w =sc.nextDouble();
        double h =sc.nextDouble();
        //求出BMI指数
        double bmi = w / (h * h);
        //定义一个变量r来保存最终结果
        String r = "";
        //根据 bmi 指数范围,来给r重新赋值
        if (bmi < 18.5) {
            r = "过轻";
        } else if (bmi <= 22.9) {
            r = "正常";
        } else if (bmi <= 24.9) {
            r = "偏胖";
        } else if (bmi <= 29.9) {
            r = "肥胖";
        } else if (bmi <= 40) {
            r = "重度肥胖";
        } else {
            r = "极度肥胖";
        }
        System.out.println("您的BMI指数:" + bmi);
        System.out.println("您的体重属于:" + r);

    }

    void demo11(){
        List list =new ArrayList();
        for (int i=1;i<100;i++){
            if((i+3)%5==0&&(i-3)%6==0){
                list.add(i);
            }
        }
        System.out.println(list.get(0));
    }

    void demo12(){
        List list =new ArrayList();
        for (int i=400;i<=500;i++){
            if (i%2==1&&i%5==3&&i%9==1){
                list.add(i);
            }
        }
        System.out.println(list);

    }
    void demo13(){
        List list = new ArrayList();
        for (int i=1000;i<10000;i++){
            if (((i/100)%10)==3&&((i/10)%10)==6&&i%2==0&&i%3==0){
                list.add(i);
            }
        }
        System.out.println(list);
        System.out.println("最小的:"+list.get(0)+"\t最大的:"+list.get(list.size()-1));
    }

    void demo14(){
        List list = new ArrayList();
        for (int i=1000;i<10000;i++){
            if (i*(i/1000)==(i%10)*1000+((i/10)%10)*100+((i/100)%10)*10+i/1000){
                list.add(i);
            }
        }
        System.out.println(list);
    }

    void demo15(){
        List list = new ArrayList();
        for (int i=100;i<1000;i++){
            if(i/11==i/100+(i/10)%10+i%10){
                list.add(i+" 商:"+i/11);
            }
        }
        System.out.println(list);
    }

    void demo16(){
        List list = new ArrayList();
        for (int i=0;i<100000;i++){
            int shang=i/80;
            if(shang%7==0 && shang%2==1 && shang%3==1 && shang%4==1 && shang%5==1 && shang%6==1){
                list.add(i);
            }
        }
        System.out.println(list);
    }

    void demo17(){
        List list =new ArrayList();
        for (int i=1;i<=10000;i++){
            for (int j=1;j<=i;j++) {
                if (i*j==140){
                        list.add("j/i="+j+"/"+i);
                    }
                }
        }
        System.out.println(list);
    }

    void demo18(){
        List list = new ArrayList();
        for (int i=10000;i<100000;i++){
            if((i+(7*100000))==((i*10)+7)*5){
                list.add("该五位数数为:"+i);
            }
        }
        System.out.println(list);
    }

    void demo19(){
        for (int i=1;i<=9;i++){
            int a=123456789;

        }
    }

    void demo20(){

    }

    void demo21(){

    }

    void demo22(){
        System.out.println("输入你所想要查证的三位数字:");
        Scanner sc  = new Scanner(System.in);
        int x =sc.nextInt();
        int a=x/100;
        int b=x/10%10;
        int c=x%10;
        if(x==(a*a*a)+(b*b*b)+(c*c*c)){
            System.out.println(x+"是水仙花数");
        }
        else {
            System.out.println(x+"不是水仙花数");
        }
    }

    void demo23(){

    }

    void demo24(){

    }
    
    public static void main(String[] args) {
        Main m = new Main();
//        m.demo01();
//        m.demo02();
//        m.demo03();
//        m.demo04();
//        m.demo05();
//        m.demo06();
//        m.demo07();
//        m.demo08();
//        m.demo09();
//        m.demo10();
//        m.demo11();
//        m.demo12();
//        m.demo13();
//        m.demo14();
//        m.demo15();
//        m.demo16();
//        m.demo17();
//        m.demo18();
//        m.demo19();
//        m.demo20();
//        m.demo21();
//        m.demo22();
//        m.demo23();
//        m.demo24();

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值