• 第五周上机练习


    1.

    package test;
    public class LH {
    
        public static void main(String[] args) {
            int i;
            for(i=100;i<1000;i++){
                int b=i/100;
                int s=i/10%10;
                int g=i%10;
                if(i==g*g*g+b*b*b+s*s*s){
                    System.out.println(i);
                }
            }
      }
    }

    2.

    package test;
    
    public class LH {
    
        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 test;
    
    public class LH {
    
        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 test;
    
    public class LH {
    
        public static void main(String[] args) {
            for (int i = 1; i <= 6; i++) {
                for (int l = 1; l < 7 - i; l++) {
                    System.out.print(" ");
                }
                for (int j = i; j > 0; j--) {
                    System.out.print(j);
                }
                System.out.println();
            }
        }
    }
    package test;
    
    public class LH {
    
        public static void main(String[] args) {
            int i, j, n;
            for (i = 6; i > 0; i--) {
                for (n = 0; n <= 6 - i; n++) {
                    System.out.print(" ");
                }
                for (j = 1; j <= i; j++) {
                    System.out.print(j);
                }
                System.out.println();
            }
    
        }
    }

    3.

    package test;
    
    import java.util.*;
    
    public class LH {
    
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.println("请输入年份:");
            int year = input.nextInt();
            System.out.println("请输入月份:");
            int month = input.nextInt();
            System.out.println("请输入日子:");
            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.

    package test;
    import java.util.Scanner;
    public class LH {
          public static void main(String[] args) {
              Scanner sc = new Scanner(System.in);
              System.out.println("请输入一个四位数:");
              int i = sc.nextInt();
              int q = i/1000%10;
              int b = i/100%10;
              int s = i/10%10;
              int g = i%10;
              int n;
              reverse = g*1000+s*100+b*10+q;
              System.out.println("反转后为:"+n);
              }
          }
  • 相关阅读:
    junit测试时,出现java.lang.IllegalStateException: Failed to load ApplicationContext
    Mybatis 3 返回布尔值,需要注意的地方
    mybatis sql in 查询
    在HTML中如何隐藏某段文字具体该怎么实现
    SpringMVC存取Session的两种方法
    spring mvc 使用session
    mybatis入门例子
    Android自定义GifView显示gif动画
    [wxWidgets]_[0基础]_[经常更新进度条程序]
    ASP.NET验证控件
  • 原文地址:https://www.cnblogs.com/z118127/p/12619190.html
Copyright © 2020-2023  润新知