zoukankan      html  css  js  c++  java
  • java第五周随堂

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

    package doom4;
    
    public class thefiveweekclasswork1 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int i = 100;
    		for (i = 100; i < 1000; i++) {
    			int ge = i % 10;
    			int shi = i / 10 % 10;
    			int bai = i / 100;
    			if (i == bai * bai * bai + shi * shi * shi + ge * ge * ge)
    				System.out.println(i + "是一个水仙花数");
    		}
    
    	}
    }
    

      

    2

    package doom4;
    
    public class thefiveweekclasswork2_1 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int i;
    		int j;
    		for (i = 1; i <= 6; i++) {
    			for (j = 1; j <= i; j++) {
    				System.out.print(j);
    			}
    			System.out.println();
    		}
    
    	}
    
    }
    

      

    package doom4;
    
    public class thefiveweekclasswork2_2 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int i;
    		int j;
    		for (i = 1; i <= 6; i++) {
    			for (j = 1; j <= 7 - i; j++) {
    				System.out.print(j);
    			}
    			System.out.println();
    		}
    
    	}
    
    }
    

      

    package doom4;
    
    public class thefiveweekclasswork2_3 {
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int i;
    		int j;
    		for (i = 1; i <= 6; i++) {
    			for (j = 1; j <= 7 - i; j++) {
    				System.out.print(" ");
    			}
    			for (j = i; j >= 1; j--)
    				System.out.print(j);
    			System.out.println();
    		}
    		System.out.println();
    
    	}
    
    }
    

      

    package doom4;
    
    public class thefiveweekclasswork2_4 {
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int i;
    		int j;
    		for (i = 1; i <= 6; i++) {
    			for (j = 1; j <= i; j++) {
    				System.out.print(" ");
    			}
    
    			for (j = 1; j <= 7 - i; j++) {
    				System.out.print(j);
    			}
    			System.out.println();
    		}
    
    	}
    
    }
    

      

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

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

      

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

    package doom4;
    
    import java.util.Scanner;
    
    public class thefiveweekclasswork4 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner input = new Scanner(System.in);
    
    		System.out.print("请输入一个四位数:");
    		int x = input.nextInt();
    		int ge = x % 10;
    		int shi = x / 10 % 10;
    		int bai = x / 100 % 10;
    		int qian = x / 1000;
    		System.out.print(ge);
    		System.out.print(shi);
    		System.out.print(bai);
    		System.out.print(qian);
    
    	}
    
    }
    

      

  • 相关阅读:
    网络并发服务器设计
    linux脚本编程技术
    守护进程学习
    UDP通讯程序设计
    TCP通讯程序设计
    linux中socket的理解
    linux网络协议
    kafka ProducerConfig 配置
    crontab定时执行datax
    crontab
  • 原文地址:https://www.cnblogs.com/a000/p/12619033.html
Copyright © 2011-2022 走看看