/* The title is as follows: 1 (for Loop) * Programming to find the number of four-bit integer ABCD that satisfies the following relationship. (AB+CD) (AB+CD) =ABCD2 (loop) * read into an integer n, output such as shape n = 3 * ********n = 4 * * * * * * * * * * * * * * * * * * * * * * * * *, the number of loops in the outer loop. For each line, the thing to do: 1. Output a number of spaces; 2. Output a number of stars; 3. Line break. Hint: output does not wrap, with System.out.print () 3. (cycle) * * To find the number of daffodils. The so-called Narcissus number, refers to a three-digit ABC, if the A3+B3+C3=ABC is satisfied, then ABC is the number of daffodils. 4. (Loop) * * Enter an integer to calculate the and of the numbers on each of them. (Note: Is an integer of any bit) space: n-1 Descending asterisk: 1 3 5 2 3 4*/package Mytest;import Java.util.scanner;public class Chapunitone {//First answer Pub LIC void Answerone () {int A,b,c,d;/*int i = 1234;a = I/1000;b = i/100% 10;c = i/10% 10;d = i% 10; System.out.println (a); System.out.println (b); System.out.println (c); System.out.println (d); */for (int i = 1000;i<9999;i++) {a = I/1000;b = i/100% 10;c = i/10% 10;d = i% 10;int AB = A*10+b;int cd = C*10+d;int ad = ab+cd;if (Ad*ad = = i) {System.out.println (i);}}} Second answer public void Answertwo () {Scanner num = new Scanner (system.in); System.out.println ("Please enter an integer"); int mynum = Num.nextint (); for (int i=0; i<mynum; i++) {for (int j=0; j<=mynum-i-1; J + + ) {System.out.print (" ");} for (int j=0; j<=i*2; J + +) {System.out.print ("*");} System.out.println ();}} The third answer to public void Answerthree () {for (int i = 100;i<999;i++) {int a = i/100% 10;int B = i/10% 10;int c = i% 10;if ( A*a*a+b*b*b+c*c*c = = i) {System.out.println ("Number of Daffodils:" +i);}} Question fourth answer public void Answerfour () {Scanner num = new Scanner (system.in); System.out.println ("Please enter an integer:"); int mynum = Num.nextint (); int sum = 0;/* int a = i/100% 10; int b = I/10% 10; int c = i% 10;*/system.out.print ("Sum ="), while (mynum>0) {int temp = Mynum%10;sum + = Mynum%10;mynum = Mynum/10;if (Myn Um!=0) System.out.print (temp+ "+"); ElseSystem.out.print (temp);} System.out.println ("=" +sum);} public static void Main (string[] args) {Scanner i = new Scanner (system.in); System.out.println ("Please enter the question number you want to see the answer:"); int num = I.nextint (); Chapunitone myanswer = new Chapunitone (); switch (num) {case 1:myanswer. Answerone (); Break;case 2:myanswer. Answertwo (); Break;case 3:myanswer. Answerthree (); Break;case 4:myanswer. Answerfour (); break;}}}
Java Beginner Practice Answer (Loop)