zoukankan      html  css  js  c++  java
  • 第五周上机作业

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

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) { 
             int a,b,c;
              System.out.println("三位数中所有水仙花数:");
              for(int n = 100;n<1000;n++){
                  a=n/100;
                  b=n%100/10;
                  c=n%10;
                  if(a*a*a+b*b*b+c*c*c==n){
                      System.out.println(n);
                  }
              }
            
            }
        }

     

     

     

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

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) { 
              for(int i=1;i<=6;i++){
                  for(int j=1;j<=i;j++){
                      System.out.print(j);
                  }
                System.out.println();  
              }
            }
        }

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) { 
              for(int i=6;i>=1;i--){
                  for(int j=1;j<=i;j++){
                      System.out.print(j);
                  }
                System.out.println();  
              }
            }
        }

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) {    
             for (int i = 1; i <= 6; i++)
                {
                    for (int j = 6; j > i; j--)
                    {
                        System.out.print(" ");
                    }
                    for (int j = i; j > 0; j--)
                    {
                        System.out.print(j);
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) {    
             for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        System.out.print(" ");
                    }
                    for (int j = 1; j <= 6 - i; j++)
                    {
                        System.out.print(j);
                    }
                    System.out.println();
                }
            }
        }

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

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) { 
            Scanner input=new Scanner(System.in);
            System.out.println("year");
            int year = input.nextInt();
            
            System.out.println("month");
            int month = input.nextInt();
            
            System.out.println("day");
            int day = input.nextInt();
            int total=0;
            for (int i=1;i<month;i++){
                switch(i){
                case 4:
                case 6:
                case 9:
                case 11:
                    total+=30;
                    break;
                case 2:
                    if(year%4==0&&year%100!=0||year%400==0)
                        total+=29;
                    else
                            total+=28;
                            break;
                default:
                    total+=31;
                    break;
                    }
                }
                total+=day;
                System.out.println("该天是第"+total+"天");
            }
            
            }

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

    package com.itheima01;
    import java.util.Scanner;
    public class Day01 {
    
        public static void main(String[] args) { 
             Scanner sc = new Scanner(System.in);
             System.out.println("请输入一个四位数");
             int i = sc.nextInt();
             if(i>=1000&&i<10000){
                 int ge = i%10;
                 int shi = i%100/10;
                 int bai = i%1000/100;
                 int qian = i/1000;
                 int sum = qian+bai*10+shi*100+ge*1000;
                 System.out.println(sum);
             }else{
                 System.out.println("NO!");
             }
    
            }
        }

  • 相关阅读:
    filter的用法
    刚下载好的 vscode 不能运行,一片黑 以及终端不能输入 解决办法
    JS获取光标在input 或 texterea 中下标位置
    JS 数组去重
    字符串操作函数:JSON.parse()、JSON.stringify()、toString 的区别,字符串转数组 str.split(','),数组转字符串String(),以及对象拼接合并Object.assign(),数组拼接合并concat()
    创建标准化工程目录脚本
    configParse模块
    json与api- 天气api 博客词频分析
    文件读写
    os模块、文件压缩 、匹配文件后缀名:fnmatch glob
  • 原文地址:https://www.cnblogs.com/zhangjiatong/p/12619000.html
Copyright © 2011-2022 走看看