第五次上机作业

//1. 打印出所有的"水仙花数",
1.
package javazuoye;
//import java.util.Scanner;
public class Dsizhou {
    public static void main(String[] args) {
        int x,y,z;//x为个位  y为十位  z为百位
        for(int i=100;i<=999;i++)
        {
            x=i%10;//个位
            y=i/10%10;//十位
            z=i/100;//百位
            if(i==(x*x*x)+(y*y*y)+(z*z*z))
            {
                System.out.println("水仙花数为"+i);
            }
        }
    }
        
}
//在控制台输出以下图形
package javazuoye;
//import java.util.Scanner;
public class Dsizhou {
    public static void main(String[] args) {
        for(int i=1;i<=7;i++) {
            System.out.println(" ");
            for(int z=1;z)
            {
                System.out.print(z);
            }
        }
        }
}
package javazuoye;
//import java.util.Scanner;
public class Dwuzhouzuoye {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        //Scanner input=new Scanner(System.in);
        //int x=input.nextInt();
        for(int i=1;i<7;i++) {
            for(int z=1;z<=7-i;z++) {
                System.out.print(z);
            }
            System.out.println();
      }

    }

}
package javazuoye;
//import java.util.Scanner;
public class Dwuzhouzuoye {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        //Scanner input=new Scanner(System.in);
        //int x=input.nextInt();
        for(int i=1;i<7;i++) {
            for(int z=i;z>0;z--) {
                System.out.print(z);
            }
            System.out.println();
      }
    }

}
package javazuoye;
//import java.util.Scanner;
public class Dwuzhouzuoye {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        //Scanner input=new Scanner(System.in);
        //int x=input.nextInt();
        for(int i=6;i>0;i--) {
            for(int z=0;z<6-i;z++) {
                System.out.print(" ");
            }
            for(int a=1;a<=i;a++) {
                System.out.print(a);
            }
            System.out.println("");
        }
    }

}
//3. 输入年月日,判断这是这一年中的第几天
package javazuoye;
import java.util.Scanner;
public class Dsizhou {
    public static void main(String[] args) {
        System.out.println("请输入年月日");
        Scanner  input=new Scanner(System.in);
        System.out.println("请输入年");
        int x=input.nextInt();
        System.out.println("请输入月");
        int y=input.nextInt();
        System.out.println("请输入日");
        int z=input.nextInt();        
        int sum=0;
        if(x%4==0&&x%100!=0)
        {
            switch(y)
            {
            case 1: sum=z;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 2: sum=z+31;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 3: sum=z+60;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 4: sum=z+91;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 5: sum=z+121;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 6: sum=z+152;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 7: sum=z+183;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 8: sum=z+213;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 9: sum=z+244;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 10: sum=z+274;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 11:  sum=z+305;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 12: sum=z+335;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            default:
                System.out.println("输入错误");
                break;
            }
        }
        else 
        {

            switch(y)
            {
            case 1: sum=z;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 2: sum=z+31;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 3: sum=z+59;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 4: sum=z+90;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 5: sum=z+120;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 6: sum=z+151;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 7: sum=z+182;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 8: sum=z+212;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 9: sum=z+243;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 10: sum=z+273;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 11:  sum=z+304;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            case 12: sum=z+334;
            System.out.println(x+"年"+y+"月"+z+"日是第"+sum+"天");
            break;
            default:
                System.out.println("输入错误");
                break;
            }
        
            
        }
    }
}
//由控制台输入一个4位整数,求将该数反转以后的数,
package javazuoye;
import java.util.Scanner;
public class Dwuzhouzuoye {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        //Scanner input=new Scanner(System.in);
        //int x=input.nextInt();
        int a, b, c, d, e, x;
        Scanner sc = new Scanner(System.in);
        System.out.println("输入数字:");
        e = sc.nextInt();
        a = e / 1000;
        b = e / 100 % 10;
        c = e / 10 % 10;
        d = e % 10;
        x = d * 1000 + c * 100 + b * 10 + a;
        System.out.println("反转后数为:" + x);
    }

}

 

你可能感兴趣的:(第五次上机作业)