• 第五周作业



    1. 打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。(知识点:循环语句、条件语句

    import java.util.Scanner;
    
    public class nn {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            for(int a=100;a<1000;a++) {
                int gw=a%10;
                int sw=a/10%10;
                int bw=a/100;
                if(gw*gw*gw+sw*sw*sw+bw*bw*bw==a) {
                    System.out.println(a);
                }
            }
        }
    }


    2.在控制台输出以下图形(知识点:循环语句、条件语句)

    import java.util.Scanner;
    
    public class nn {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
             for(int a = 1;a <= 6;a++)
                {
                    for(int i = 1;i <= a;i++)
                        System.out.printf("%d ",i);
                    System.out.print("
    ");
                }
                System.out.print("
    ");
                 
                for(int a = 6;a >= 1;a--)
                {
                    for(int i = 1;i <= a;i++)
                        System.out.printf("%d ",i);
                    System.out.print("
    ");
                }
                System.out.print("
    ");
                 
                for(int a = 1;a <= 6;a++)
                {  
                    for(int i = 1;i <= 2 * (6 - a);i++)
                        System.out.print(" ");
                     
                    for(int i = a;i >= 1;i--)
                        System.out.printf("%d ",i);
                    System.out.print("
    ");
                }
                System.out.print("
    ");
                 
                for(int a = 6;a >= 1;a--)
                {
                    for(int i = 1;i <= 2 *(6-a);i++)
                        System.out.print(" ");
                    for(int i = 1;i <= a;i++)
                        System.out.printf("%d ",i);
                    System.out.print("
    ");
                }
        }
    }

    3. 输入年月日,判断这是这一年中的第几天(知识点:循环语句、条件语句)

    import java.util.Scanner;
    
    public class nn {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
             int x = 0;
                Scanner sc=new Scanner(System.in);
                System.out.print("请输入年份");
                int year=sc.nextInt();
                System.out.print("请输入月份");
                int month=sc.nextInt();
                System.out.print("请输入日期");
                int date= sc.nextInt();
                if(year%4==0 && year%100!=0 || year%400==0) {
                    switch(month) {
                    case 1:  x=31; break;
                    case 2:  x=31+29;break;
                    case 3:  x=31+29+31;break;
                    case 4:  x=31+29+31+30;break;
                    case 5:  x=31+29+31+30+31;break;
                    case 6:  x=31+29+31+30+31+30;break;
                    case 7:  x=31+29+31+30+31+30+31;break;
                    case 8:  x=31+29+31+30+31+30+31+31;break;
                    case 9:  x=31+29+31+30+31+30+31+31+30;break;
                    case 10: x=31+29+31+30+31+30+31+31+30+31;break;
                    case 11: x=31+29+31+30+31+30+31+31+30+31+30;break;
                    case 12: x=31+29+31+30+31+30+31+31+30+31+30+31;break;
                    }
                }else {
                    switch(month) {
                    case 1:  x=31;break;
                    case 2:  x=31+28;break;
                    case 3:  x=31+28+31;break;
                    case 4:  x=31+28+31+30;break;
                    case 5:  x=31+28+31+30+31;break;
                    case 6:  x=31+28+31+30+31+30;break;
                    case 7:  x=31+28+31+30+31+30+31;break;
                    case 8:  x=31+28+31+30+31+30+31+31;break;
                    case 9:  x=31+28+31+30+31+30+31+31+30;break;
                    case 10: x=31+28+31+30+31+30+31+31+30+31;break;
                    case 11: x=31+28+31+30+31+30+31+31+30+31+30;break;
                    case 12: x=31+28+31+30+31+30+31+31+30+31+30+31;break;
                    }
                }
                System.out.println(year+""+month+""+date+""+"是第"+(x+date)+"");
        }
    }

    4.由控制台输入一个4位整数,求将该数反转以后的数,如原数为1234,反转后的数位4321(知识点:循环语句、条件语句)

    import java.util.Scanner;
    
    public class nn {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入一个四位数");
            int num=sc.nextInt();
            int qian=num/1000;
            int bai=num/100%10;
            int shi=num/10%10;
            int ge=num%10;
            System.out.println("原先的数为:"+num+"现在的为"+(qian+bai*10+shi*100+ge*1000));
        }
    }

  • 相关阅读:
    黑马前端2020就业Web全套课-2020.4月最新版
    什么是Redis雪崩、穿透和击穿? 全面掌握Redis
    ElasticStack高级搜索入门到项目实战,Elasticsearch全文检索
    阿里云盘邀请码+软件下载
    Intellij IDEA超实用设置汇总,高效便捷敲代码
    双11的亿级高并发架构,是怎么设计的?
    TensorFlow 卷积神经网络实用指南 | iBooker·ApacheCN
    TensorFlow 入门 | iBooker·ApacheCN
    TensorFlow 2.0 快速入门指南 | iBooker·ApacheCN
    深度学习快速参考 | iBooker·ApacheCN
  • 原文地址:https://www.cnblogs.com/nmzAmbition/p/12618541.html
Copyright © 2020-2023  润新知