1.
package test; public class LH { public static void main(String[] args) { int i; for(i=100;i<1000;i++){ int b=i/100; int s=i/10%10; int g=i%10; if(i==g*g*g+b*b*b+s*s*s){ System.out.println(i); } } } }
2.
package test; public class LH { public static void main(String[] args) { for(int i=1;i<=6;i++){ for(int j=1;j<=i;j++){ System.out.print(j); } System.out.println(); } } }
package test; public class LH { public static void main(String[] args) { for(int i=6;i>=1;i--){ for(int j=1;j<=i;j++){ System.out.print(j); } System.out.println(); } } }
package test; public class LH { public static void main(String[] args) { for (int i = 1; i <= 6; i++) { for (int l = 1; l < 7 - i; l++) { System.out.print(" "); } for (int j = i; j > 0; j--) { System.out.print(j); } System.out.println(); } } }
package test; public class LH { public static void main(String[] args) { int i, j, n; for (i = 6; i > 0; i--) { for (n = 0; n <= 6 - i; n++) { System.out.print(" "); } for (j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } } }
3.
package test; import java.util.*; public class LH { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入年份:"); int year = input.nextInt(); System.out.println("请输入月份:"); int month = input.nextInt(); System.out.println("请输入日子:"); int day = input.nextInt(); int total = 0; for (int i = 1; i < month; i++) { switch (i) { case 4: case 6: case 9: case 11: total += 30; break; case 2: if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) total += 29; else total += 28; break; default: total += 31; break; } } total += day; System.out.println("该天是第" + total + "天"); } }
4.
package test; import java.util.Scanner; public class LH { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个四位数:"); int i = sc.nextInt(); int q = i/1000%10; int b = i/100%10; int s = i/10%10; int g = i%10; int n; reverse = g*1000+s*100+b*10+q; System.out.println("反转后为:"+n); } }