4月2日java作业

1.
package Dmh;
/*
 * 水仙花数
 */
public class zy0402 {

    public static void main(String[] args) {
        int i ;
        int ge;
        int shi;
        int bai ;
        for ( i = 100; i < 1000; i++) {
             ge = i%10;
            shi  = i/10%10;
            bai = i/100;
            if(ge*ge*ge+shi*shi*shi+bai*bai*bai==i){
                System.out.println();
            }
            
        }
    }

}
2.
package Dmh;
/*
 * 输出三角形
 */
public class zy0402 {
//正直角三角形
    public static void main(String[] args) {
        for (int i = 1; i < 7; i++) {
            
            for (int j = 1; j <= i; j++) {
                System.out.print(j);
            }
            System.out.println();
        }
//倒直角三角形
        for (int i = 6; i >0; i--) {
            for (int j = i; j > 0; j--) {
                System.out.print(j);
            }
            System.out.println();
        }
    }

}
3.
package Dmh;

import java.util.Scanner;

//输入年月日判断是今年第几天
public class zy0402 {

    public static void main(String[] args) {
        Scanner sca= new Scanner(System.in);
        System.out.println("输入年份");
        int year = sca.nextInt();
        System.out.println("输入月份");
        int month = sca.nextInt();
        System.out.println("输入日期");
        int days=0;
        int day = sca.nextInt();
        if ((year/4==0&&year/100!=0)||year/400==0) {
            for (int i = 0; i < month; i++) {
                if (i<4) {
                    days = day+i*30+i/2+i%2;
                }else{
                    days = day+i*30+i/2+i%2-2;
                }
                
            }
            System.out.println("今天是今年的:"+days+"");
        }else{
            for (int i = 0; i < month; i++) {
                if (i<4) {
                    days = day+i*30+i/2+i%2;
                }else{
                    days = day+i*30+i/2+i%2-1;
                }
                
            }
            System.out.println("今天是今年的:"+days+"");
        }
        
        
    }

}
4.
package Dmh;

import java.util.Scanner;

/*
 * 输入四位数之后翻转该数
 */
public class zy0402 {

    public static void main(String[] args) {
        Scanner sca= new Scanner(System.in);
        System.out.println("输入一个四位数");
        int num = sca.nextInt();
        
        int ge,shi,bai,qian;
            
            if (num<1000||num>10000) {
                System.out.println("您输入的有误");
            }else{
                qian = num/1000;
                bai = num/100%10;
                shi =num/10%10;
                ge= num%10;
                System.out.print(ge);
                System.out.print(shi);
                System.out.print(bai);
                System.out.print(qian);
            }
            
        
        
    }

}

 

你可能感兴趣的:(4月2日java作业)