• 第三次上机练习


    /*1. 打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",
    因为153=1的三次方+5的三次方+3的三次方。(知识点:循环语句、条件语句)*/
    package practice3;
    
    public class Code1 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		for (int i = 100; i <= 999; i++){
    			int ge = i%10;
    			int shi = i/10%10;
    			int bai = i/100;
    			if (i == ge*ge*ge + shi*shi*shi + bai*bai*bai){
    				System.out.println("水仙花数为:" + i);
    			}
    		}
    	}
    
    }
    

      

    //在控制台输出以下图形(知识点:循环语句、条件语句)
    /*(1)1      (2)123456     (3)1 (4)123456
     *   12        12345        21     12345
     *   123       1234        321      1234
     *   1234      123        4321       123
     *   12345     12        54321        12
     *   123456    1        654321         1
     */
    package practice3;
    
    public class Code2 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    	//(1)
    		for (int i = 1; i <= 6; i++){
    			for (int j = 1; j <= i; j++){
    				System.out.print(j);				
    			}
    			System.out.print("
    ");
    		}
    	//(2)
    		for (int i = 6; i > 0; i--){
    			for (int j = 1; j <= i; j++){
    				System.out.print(j);
    			}
    			System.out.print("
    ");
    		}
    	//(3)
    		for(int i = 1; i < 7; i++) {
                for (int n = 1; n <  7-i; n++) {
                    System.out.print(" ");
                }
                for(int j = i; j > 0; j--) {
                    System.out.print(j);
                }
                System.out.println();
            }
    	//(4)
    		for(int i = 6; i > 0; i --) {
                for(int k = 0; k < 6-i; k++) {
                    System.out.print(" ");
                }
                for(int j = 1; j <= i; j++) {
                    System.out.print(j);
                }
               System.out.println(" ");
            }
    	}
    
    }
    

      

    //3. 输入年月日,判断这是这一年中的第几天(知识点:循环语句、条件语句)
    package practice3;
    
    import java.util.Scanner;
    
    public class Code3 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Scanner input = new Scanner(System.in);
            System.out.print("year:");
            int year = input.nextInt();
            System.out.print("month:");
            int month = input.nextInt();
            System.out.print("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 practice3;
    
    import java.util.Scanner;
    
    public class Code4 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Scanner input=new Scanner(System.in);
            System.out.print("input:");
            int a = input.nextInt();
            int b , c , d , e;
            b = a % 10;
            c = a % 100 / 10;
            d = a % 1000 / 100;
            e = a / 1000;
            System.out.println("output:" + b + c + d + e);
    	}
    
    }
    

      

  • 相关阅读:
    判断二叉树是否是完全二叉树
    二叉搜索树的第k个节点
    二叉树的深度
    二叉搜索树与双向链表
    二叉搜索树的后序遍历序列
    poj 2192 (DP)
    poj 1159 (DP LCS)
    poj 1934(LCS)
    《编程之美》读书笔记 -- 1.2中国象棋问题
    poj 1050(DP)
  • 原文地址:https://www.cnblogs.com/wu-di-821-821/p/12619148.html
Copyright © 2020-2023  润新知