• 第五周作业


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

     1 public class wyy {
     2 
     3     /**
     4      * @param args
     5      */
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         for (int num=100;num<1000;num++) 
     9         { 
    10             int gw=num%10;
    11             int sw=num/10%10;
    12             int bw=num/100%10;
    13             if (gw*gw*gw+sw*sw*sw+bw*bw*bw==num) 
    14             { 
    15                 System.out.println(num);
    16             }
    17         }
    18     }
    19 }

     2.在控制台输出以下图形(知识点:循环语句、条件语句)

     1 import java.util.*;
     2 public class wyy {
     3 
     4     /**
     5      * @param args
     6      */
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9         for(int i=1;i<=6;i++){
    10             for(int j=1;j<=i;j++){
    11                 System.out.print(j);
    12             }
    13             System.out.println("");
    14         }
    15         System.out.println("---------------");
    16     }
    17 }

     1 import java.util.*;
     2 public class wyy {
     3 
     4     /**
     5      * @param args
     6      */
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9          for(int i=1;i<=7;i++){
    10                 for(int j=1;j<=7-i;j++){
    11                     System.out.print(j);
    12                 }
    13                 System.out.println("");
    14             }
    15             System.out.println("---------------");
    16     }
    17 }

     1 import java.util.*;
     2 public class wyy {
     3 
     4     /**
     5      * @param args
     6      */
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9         for(int i=1;i<7;i++) {
    10             for (int k = 1; k <7-i ; k++) {
    11                 System.out.print(" ");
    12             }
    13             for(int j=i;j>0;j--) {
    14                 System.out.print(j);
    15             }
    16             System.out.println();
    17         }
    18     }
    19 }

     1 import java.util.*;
     2 public class wyy {
     3 
     4     /**
     5      * @param args
     6      */
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9          for(int i=1;i<=6;i++){
    10                 for(int k=0;k<i;k++){
    11                     System.out.print(" ");
    12                 }
    13                 for(int j=1;j<=7-i;j++){
    14                     System.out.print(j);
    15                 }
    16                 System.out.println("");
    17             }
    18     }
    19 }

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

     1 import java.util.*;
     2 public class wyy {
     3 
     4     /**
     5      * @param args
     6      */
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9         Scanner input = new Scanner(System.in);
    10         System.out.println("分别输入年月日:");
    11         System.out.print("输入年份:");
    12         int year = input.nextInt();
    13         System.out.print("输入月份:");
    14         int month = input.nextInt();
    15         System.out.print("输入本月日期:");
    16         int data = input.nextInt();
    17         int sum = 0;
    18         
    19         for (int i = 1; i < month; i++) {
    20             switch (i) {
    21             case 1:
    22             case 3:
    23             case 5:
    24             case 7:
    25             case 8:
    26             case 10:
    27             case 12:
    28                 sum = sum +31;
    29                 continue;
    30             case 4:
    31             case 6:
    32             case 9:
    33             case 11:
    34                 sum = sum + 30;
    35                 continue;
    36             }
    37         }
    38         if (year%4==0&&month>2) {
    39             sum = sum +29;
    40         }else if (month>2){
    41             sum = sum +28;
    42         }
    43         sum = sum + data;
    44         System.out.println("今天是"+year+"年的第"+sum+"天");
    45     }
    46 }
    47         

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

     1 import java.util.*;
     2 public class wyy {
     3 
     4     /**
     5      * @param args
     6      */
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9         Scanner sc = new Scanner(System.in);
    10            int x = sc.nextInt();
    11            if(x>999 && x<=9999){
    12                int gewei = x%10;
    13                int shiwei = x % 100 / 10;
    14                int baiwei = x%1000/100;
    15                int qianwei = x/1000;
    16                int sum = qianwei + baiwei*10 +shiwei*100 +gewei*1000;
    17                System.out.println(sum);
    18            }
    19            else{
    20                System.out.println("输入错误");  
    21            }
    22              
    23     }
    24 }

  • 相关阅读:
    网站架构探索(3)负载均衡的方式
    架构师之路(6)OOD的开闭原则
    也谈IT人员流失问题 王泽宾
    技术体系的选择之Java篇
    网站架构探索(2)CDN基本常识
    设计模式之单例模式
    网站架构探索(1)序言 王泽宾
    架构师之路(39)IoC框架
    发展之道:简单与专注
    修me30打印机
  • 原文地址:https://www.cnblogs.com/WangYYY/p/12618799.html
Copyright © 2020-2023  润新知