1 /*2 output All "daffodils" on the console3 Narcissus: 100~9994 5 in the above number range: this number = single digit * digit * digit + 10 bit * 10 bit * 10 bit + hundred * Hundred * Hundred6 7 Example: xyz=x^3 +y^3 +z^38 9 How to split a three-digit number into every integerTen One idea: Hundred: int x= i/100 A 10-bit: int y = I/10 - digit: int z = i% - the */ - classLoopTest3 { - Public Static voidMain (string[] args) - { + for(inti=100; i<=999; i++ ){ - intx= i/100; + inty = i/10% 10; A intz = i% 10; at - //The number itself is I, X, Y, Z is the hundred 10 digit digit - if(i = = x* x* x+ y* y* y+ z* z*z) { -System.out.println (i);//i=153,370,371,407 - - //153=1^3+ 5^3 +3^3=1 + 125+ in } - } to } +}
--------------------------------------------------------------------------------------------------------------- -----------------
1 ImportJava.util.Scanner;2 3 /*4 Yang Hui triangle: each element of the current row is the top row of the element in the current row and the left element of the previous row and5 6 Analysis:7 8 This topic uses the following skill points:9 Ten for Loop: Two nesting for loops One Dynamic Data: The last line of this element and the left element of the previous row A static data: The first and last columns of each row are: 1 - - The elements of the array can be quickly positioned with the subscript index, assigned the - control a two-dimensional array with two for loops to get the final result - - Objective: + - Expand the field of vision of the students, do not require mastery, need to understand. Be able to understand, finish mastering later. + A at 1 1 - 1 2 1 - 1 3 3 1 - 1 4 6) 4 1 - 1 5 5 1 - in */ - classYanghui { to Public Static voidMain (string[] args) { + int[] san =New int[6] [6]; - the //I would do triangles, I would do rectangles, assign values to triangles static data 1 * for(inti = 0; i<6; i++) {//Control Line $ for(intj = 0; j<=i; J + +) {//Control ColumnsPanax NotoginsengSAN[I][J] = 1; - } the } + A //assignment of Dynamic Data for two-dimensional arrays the for(inti = 2; i<6; i++){ + for(intj = 1; j<=i-1; J + +){ - //The previous line now the code is executed here, can we go back? Can be on a row this data can be defined with the subscript of a two-dimensional array $SAN[I][J] = San[i-1][j] + san[i-1][j-1]; $ } - } - the for(inti = 0; i<6; i++) {//Control Line - for(intj = 0; j<= i; J + +) {//Control ColumnsWuyiSystem.out.print (San[i][j] + ""); the } - System.out.println (); Wu } - } About}
Java Implementation (code)--Narcissus number + Yang Hui triangle