1. 打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。(知识点:循环语句、条件语句)
1 package dfishf; 2 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 int ge,shi,bai; 8 for(int i=100;i<=999;i++){ 9 ge=i%10; 10 shi=i%100/10; 11 bai=i/100; 12 if(ge*ge*ge+shi*shi*shi+bai*bai*bai==i){ 13 System.out.println("所有水仙花数为:"+i); 14 } 15 } 16 17 } 18 }
2.在控制台输出以下图形(知识点:循环语句、条件语句)
1 package dfishf; 2 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 for(int i=1;i<=7;i++) { 8 for(int j=1;j<i;j++) { 9 System.out.print(j); 10 } 11 System.out.println(); 12 } 13 } 14 }
1 package dfishf; 2 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 for(int n=1;n<=7;n++){ 8 for(int i=6;i>=1;i--){ 9 for(int j=1;j<=i;j++){ 10 System.out.print(j); 11 } 12 System.out.println(); 13 } 14 } 15 } 16 }
1 package dfishf; 2 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 for (int i = 1; i <= 6; i++) { 8 for (int l = 1; l < 7 - i; l++) { 9 System.out.print(" "); 10 } 11 for (int j = i; j > 0; j--) { 12 System.out.print(j); 13 } 14 System.out.println(); 15 } 16 } 17 }
1 package dfishf; 2 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 int l; 8 for (int i = 6; i > 0; i--) { 9 for (l = 0; l <= 6 - i; l++) { 10 System.out.print(" "); 11 } 12 for (int j = 1; j <= i; j++) { 13 System.out.print(j); 14 } 15 System.out.println(); 16 } 17 } 18 }
3. 输入年月日,判断这是这一年中的第几天(知识点:循环语句、条件语句)
1 package dfishf; 2 import java.util.Scanner; 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 Scanner input=new Scanner(System.in); 8 System.out.print("输入年份:"); 9 int n=input.nextInt(); 10 System.out.print("输入月份:"); 11 int y=input.nextInt(); 12 System.out.print("输入日期:"); 13 int r=input.nextInt(); 14 int total=0; 15 for(int i=1;i<y;i++){ 16 switch(i){ 17 case 4: 18 case 6: 19 case 9: 20 case 11: 21 total+=30; 22 break; 23 case 2: 24 if(n%4==0&&n%100!=0||n%400==0){ 25 total+=29;} 26 else{ 27 total+=28;} 28 break; 29 default: 30 total+=31; 31 break; 32 } 33 }total+=r; 34 System.out.println("一年中第"+total+"天"); 35 } 36 }
4.由控制台输入一个4位整数,求将该数反转以后的数,如原数为1234,反转后的数位4321(知识点:循环语句、条件语句)
1 package dfishf; 2 import java.util.Scanner; 3 public class wwww { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 System.out.println("输入一个4位数:"); 8 Scanner input = new Scanner(System.in); 9 int i = input.nextInt(); 10 int q = i / 1000; 11 int b= i / 100 % 10; 12 int s= i / 10 % 10; 13 int g= i % 10; 14 System.out.println("原数为:" + i + "转换为" + (q+ b * 10 + s * 100 + g * 1000)); 15 } 16 }
原文:https://www.cnblogs.com/2463594061ab----/p/12619721.html