1. Print out all the "number of Narcissus", the so-called "Narcissus number" refers to a three-digit number, which is equal to the digits of the cube and the number itself. For example: 153 is a "Narcissus number", because cubic cubic cubic +3 +5 1 = 153. (Knowledge Point: Loops, conditional statements)
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int a,b,c,sum=0; for(int i=100;i<=999;i++) { a=i/100; b=i/10%10; c=i%10; sum=a*a*a+b*b*b+c*c*c; if(sum==i) { System.out.print(i+" "); } } } }
2. The following graphic output in the console (knowledge: Loops, conditional statements)
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); for(int a=1;a<7;a++) { for(int b=1;b<=a;b++) { System.out.print(b); } System.out.println(); } } }
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); for(int a=1;a<7;a++) { for(int b=1;b<=7-a;b++) { System.out.print(b); } System.out.println(); } } }
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); for(int a=1;a<7;a++) { for(int b=a;b>0;b--) { System.out.print(b); } System.out.println(); } } }
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); for(int a=6;a>0;a--) { for(int b=0;b<6-a;b++) { System.out.print(" "); } for(int i=1;i<=a;i++) { System.out.print(i); } System.out.println(""); } } }
3. Enter the date, to determine which is the first day of the year (knowledge points: Loops, conditional statements)
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int day=0; int month=0; int year=0; int sum=0; int leap; System.out.println("请输入年,月,日"); Scanner intput=new Scanner(System.in); year= Input.nextInt (); month The = input.nextInt (); Day = input.nextInt (); Switch (month The) / * First calculate the total number of days before a month month * / { Case . 1 : SUM = 0; BREAK ; Case 2 : SUM = 31 is; BREAK ; Case . 3 : SUM = 59; BREAK ; Case . 4 : SUM = 90; BREAK ; Case 5: sum=120;break; case 6: sum=151;break; case 7: sum=181;break; case 8: sum=212;break; case 9: sum=243;break; case 10: sum=273;break; case 11: sum=304;break; case 12: sum=334;break; default: System.out.println("请正确的输入年,月,日");break; } sum=sum+day; if(month>=0&&month<=12&&day>=1&&day<=31) { if(year%400==0||year%4==0&&year%100!=0) { leap=1; }else{ leap=0; } if(LEAP == 1 && month The> 2 ) { SUM ++ ; System.out.println (year + "of" + month + "month" + day + "number is the year of the first" + sum + "days." ); } the else { System.out.println (year + "of" + month + "month" + day + "number is the year of the first" + sum + "days." ); } } } }
4 . An input from the console . 4 bit integer after the number of inversions required, such as the original number 1234 , the number of bits after inversion 4321 (knowledge: loop statements, conditional statements)
import java.util.*; public class C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int a, b, c, d, Y, x; Scanner sc = new Scanner(System.in); System.out.println("请输入数字:"); Y = sc.nextInt(); a = Y / 1000; b = Y / 100 % 10; c = Y / 10 % 10; D = 10% the Y ; X = C * D * 1000 + 100 + 10 * B + A; System.out.println ( "inverted after number:" + X); } }