I don't know why. I may not be able to concentrate when I relax. The two simple questions just took an hour and my start point was too low. Although it is necessary to practice programming more, it is also a matter of white. It would be a little more efficient to be fully engaged in your work. Is this the reason?
Exercise 9: output the num item data before the Fibonacci. Of course, int is used here, which will overflow. I marked my mistakes. The details of these things are too difficult to do and I cannot learn them myself.
Public class Fibonacci {public static void output (INT num) {int I = 1, j = 1; if (Num <1) {system. out. println ("Please input number at least 1"); return;} system. out. print (I + ""); While (Num> 1) {system. out. print (J + ""); // an error such as J + ''may occur !!! J = I + J; I = J-I; num --;} return;} public static void main (string [] ARGs) {If (ARGs. length! = 1) {system. Out. println ("Please input a number"); return;} output (New INTEGER (ARGs [0]);}
Exercise 10: Vampire numbers. Output the four-digit vampire number.
public class XiXueGui{public static void main(String[] args){int number=0;Outer:for(int i=1001;i<9999;i++){if(i%100==0){continue;}char[] a;//a=Integer.toString(i).toCharArray();a=(""+i).toCharArray();for(int j=0;j<4;j++)for(int k=0; k<4;k++){if(k==j){continue;}for(int m=0;m<4;m++){if(m==k || m==j){continue;}if(((a[j]-'0')*10+(a[k]-'0'))*((a[m]-'0')*10+(a[6-j-k-m]-'0'))==i){System.out.println(number+" "+i+"="+((a[j]-'0')*10+(a[k]-'0'))+"*"+((a[m]-'0')*10+(a[6-j-k-m]-'0')));number++;continue Outer;}}}}}}
It will be messy, followed by char converted to int, minus '0'. When writing a program, I forget it, so an error occurs.
Ah, I have no confidence in myself.