第五周上级作业

 1 import java.util.*;
 2 public class homework 
 3 {
 4     public static void main(String[] args) {
 5         Scanner input = new Scanner(System.in);
 6         int x = 0,y = 0,z = 0;
 7         for(int i = 100;i<1000;i++) {
 8             x = i/100;
 9             y = (i%100)/10;
10             z = (i%100)%10;
11             if(x*x*x + y*y*y +z*z*z == i) {
12                 System.out.print(i+" ");
13             }
14         }
15     }
16 }






 1 import java.util.*;
 2 public class homework
 3 {
 4     public static void main(String[] args) {
 5         for(int i=1;i<=7;i++) {
 6             for(int j=1;j<i;j++) {
 7                 System.out.print(j);
 8             }
 9             System.out.println();
10         }
11     }
12 }
 1 import java.util.*;
 2 public class homework
 3 {
 4     public static void main(String[] args) {
 5           for(int i=6;i>=0;i--) {
 6                 for(int j=1;j<=i;j++) {
 7                     System.out.print(j);
 8                 }
 9                 System.out.println();
10             }
11         }
12     }
 1 import java.util.*;
 2 public class homework 
 3 {
 4     public static void main(String[] args) {
 5         for(int i=1;i<7;i++) {
 6             for(int j=i;j>0;j--) {
 7                 System.out.print(j);
 8             }
 9             System.out.println();
10         }
11     }
12 }
 1 import java.util.*;
 2 public class homework
 3 {
 4     public static void main(String[] args) {
 5           for(int i=6;i>0;i--) {
 6                 for(int k=0;k<6-i;k++) {
 7                     System.out.print(" ");
 8                 }
 9                 for(int j=1;j<=i;j++) {
10                     System.out.print(j);
11                 }
12                 System.out.println("");
13             }
14         }
15     }

输入年月日,判断这是这一年中的第几天

 1 package chap1;
 2 import java.util.Scanner;
 3 public class homework {
 4     public static void main(String[] args){
 5         int allday = 0;
 6         int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 7         Scanner read = new Scanner(System.in);
 8         System.out.print("请输入年月日:");
 9         String dateStr = read.next();
10         String[] dateInt = dateStr.split("/");
11         int year = Integer.parseInt(dateInt[0]);
12         int month = Integer.parseInt(dateInt[1]);
13         int day = Integer.parseInt(dateInt[2]);
14         for (int i = 0; i < month - 1; i++) {
15             allday += days[i];
16         }
17         allday += day;
18         if ((((year % 4 == 0 && year % 100 == 0) || year % 400 == 0) && month > 2)) {
19             allday++;
20         }
21         System.out.println(month + "月" + day + "是" + year + "年的第" + allday + "天");
22     }
23 }

由控制台输入一个4位整数,求将该数反转以后的数

 1 package chap1;
 3 public class homework{
 4     public static void main(String[] args){
 5         System.out.println("请输入一个整数:");
 6         Scanner input = new Scanner(System.in);
 7         int num=input.nextInt();
 8         int result=0;
 9         while(true)
10         {
11             int n=num%10;
12             result=result*10+n;
13             num=num/10;
14             if(num==0)
15             {
16                 break;
17             }
18         }
19         System.out.println(result);
20     }
21  
22 }
原文地址:https://www.cnblogs.com/zrz1/p/12618869.html