package com.xuexiao; public class Text5 { public static void main(String[] args) { // TODO Auto-generated method stub //1. 打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。(知识点:循环语句、条件语句) for(int i=100;i<=999;i++) { int ge = i%10; int shi = i/10%10; int bai = i/100%10; if(i == ge*ge*ge+shi*shi*shi+bai*bai*bai) { System.out.println(i); } } } }
package com.xuexiao; public class Text5 { public static void main(String[] args) { int i; int j; // TODO Auto-generated method stub //在控制台输出以下图形 for(i=1;i<=6;i++) { for(j=1;j<=i;j++) { System.out.print(j); }System.out.println(""); } } }
package com.xuexiao; public class Text5 { public static void main(String[] args) { int i; int j; // TODO Auto-generated method stub //在控制台输出以下图形 for( i=6;i>=1;i--){ for( j=1;j<=i;j++) System.out.print(j); System.out.println();} } }
package com.xuexiao; public class Text6 { public static void main(String args[]) { int i; int j; for(i = 1;i<=6;i++) { for(j = 1;j <=(6 - i);j++) System.out.print(" "); for(j=i;j>=1;j--) { System.out.print(j); }System.out.println(" "); } } }
package com.xuexiao; public class Text6 { public static void main(String args[]) { int i; int j; for(i = 6;i>=1;i--) { for(j = 1;j <=(6 - i);j++) System.out.print(" "); for(j=1;j<=i;j++) { System.out.print(j); }System.out.println(" "); } } }
package com.xuexiao; import java.util.Scanner; public class Text6 { public static void main(String args[]) { //输入年月日 判断第几天 int sum = 0; Scanner sc = new Scanner(System.in) ; System.out.println("请输入年份:"); int year = sc.nextInt(); System.out.println("请输入月份:"); int month = sc.nextInt(); System.out.println("请输入日:"); int day = sc.nextInt(); for(int i =1 ; i<month;i++) { switch(i) { case 4: case 6: case 9: case 11: sum +=30; break; case 2: if(year%4==0 && year %100!=0 || year %400 ==0) sum +=29; else sum+=28; break; default: sum +=31; break;} }sum +=day; System.out.println("该天是第"+sum+"天"); } }
package com.xuexiao; import java.util.Scanner; public class Text6 { public static void main(String args[]) { //输入四位反转 Scanner sc = new Scanner(System.in); System.out.println("请输入一个四位数:"); int i = sc.nextInt(); int a = i/1000%10; int b = i/100%10; int c = i/10%10; int d = i%10; int reverse; reverse = d*1000+c*100+b*10+a; System.out.println("反转之后的数为:"+reverse); } }