1. Print out all of the " number of Narcissus " , the so-called " number Narcissus " refers to a three-digit number, which is equal to the digits of the cube and the number itself. For example: 153 is a " number Narcissus " , since 153 = 1 cubic square + 5 cubed + 3 cubed.
package haha; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub int a=0; int b=0; int c=0; for(int i=100;i<=999;i++){ int ge=i%10; int shi=i/10%10; int bai=i/100; if(ge*ge*ge+shi*shi*shi+bai*bai*bai==i) System.out.println(i); } } }
2. The following graphic output in the console (knowledge: Loops, conditional statements)
package haha; import java.util.Scanner; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=1;i<7;i++) { for(int j=1;j<=i;j++) { System.out.print(j); } System.out.println(); } } }
package haha; import java.util.Scanner; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=1;i<7;i++) { for(int j=1;j<=7-i;j++) { System.out.print(j); } System.out.println(); } } }
package haha; import java.util.Scanner; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=1;i<7;i++) { for(int j=i;j>0;j--) { System.out.print(j); } System.out.println(); } } }
package haha; import java.util.Scanner; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=6;i>0;i--) { for(int k=0;k<6-i;k++) { System.out.print(" "); } for(int j=1;j<=i;j++) { System.out.print(j); } System.out.println(""); } } }
3. Enter the date, to determine which is the first day of the year
package haha; import java.util.Scanner; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub int x = 0; Scanner sc=new Scanner(System.in); System.out.print("请输入年份"); int year=sc.nextInt(); System.out.print("请输入月份"); int month=sc.nextInt(); System.out.print("请输入日期"); int date= sc.nextInt(); if(year%4==0 && year%100!=0 || year%400==0) { switch(month) { case 1: x=31; break; case 2: x=31+29;break; case 3: x=31+29+31;break; case 4: x=31+29+31+30;break; case 5: x=31+29+31+30+31;break; case 6: x=31+29+31+30+31+30;break; case 7: x=31+29+31+30+31+30+31;break; case 8: x=31+29+31+30+31+30+31+31;break; case 9: x=31+29+31+30+31+30+31+31+30;break; case 10: x=31+29+31+30+31+30+31+31+30+31;break; case 11: x=31+29+31+30+31+30+31+31+30+31+30;break; case 12: x=31+29+31+30+31+30+31+31+30+31+30+31;break; } }else { switch(month) { case 1: x=31;break; case 2: x=31+28;break; case 3: x=31+28+31;break; case 4: x=31+28+31+30;break; case 5: x=31+28+31+30+31;break; case 6: x=31+28+31+30+31+30;break; case 7: x=31+28+31+30+31+30+31;break; case 8: x=31+28+31+30+31+30+31+31;break; case 9: x=31+28+31+30+31+30+31+31+30;break; case 10: x=31+28+31+30+31+30+31+31+30+31;break; case 11: x=31+28+31+30+31+30+31+31+30+31+30;break; case 12: x=31+28+31+30+31+30+31+31+30+31+30+31;break; } } System.out.println(year+"年"+month+"月"+date+"日"+"是第"+(x+date)+"天"); } }
4. Enter a console by the integer 4, after the number of inversions required, such as the original number is 1234, digit reversal after 4321
package haha; import java.util.Scanner; public class heihei { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int i = sc.nextInt(); if(i>=1000&&i<10000){ int ge = i%10; int shi = i%100/10; int bai = i%1000/100; int qian = i/1000; int sum = qian+bai*10+shi*100+ge*1000; System.out.println(sum); }else{ System.out.println("ERROR!"); } } }