Thinking in Java
This program I knock out the code, with the method is very stupid feeling, will be, there is no time to think so much, have to continue to learn AH.
1 classvnum{2 Public Static voidMain (String args[]) {3Checkvampire Cvampire =NewCheckvampire ();4 for(inti=1000;i<10000;i++){5 if(Cvampire.isvampire (i)) {6 System.out.println (i);7 }8 }9 }Ten One Static classcheckvampire{ A //split num into each one, saved in numarr[] - voidEverybit (intNumintnumarr[]) { - if((1000>num) | | (10000<num)) { theNumarr[0]=numarr[1]=numarr[2]=numarr[3]=0; - return; -}Else if(num%100==0){ -Numarr[0]=numarr[1]=numarr[2]=numarr[3]=0; + return; -}Else{ +numarr[3]=num/1000; Anumarr[2]=num%1000/100; atNumarr[1]=num%100/10; -Numarr[0]=num%10; - } - } - //enter a num and the return value is true if the num is a vampire number - //because it is to detect the vampire numbers within 1000~9999, then use the exhaustive method = =, there should be a better way online in BooleanIsvampire (intnum) { - intnumeverybit[]=New int[4]; to everybit (num,numeverybit); + if(num== (numeverybit[0]*10+numeverybit[1]) * (numeverybit[2]*10+numeverybit[3])){ - return true; the } * Else if(num== (numeverybit[0]*10+numeverybit[1]) * (numeverybit[3]*10+numeverybit[2])){ $ return true;Panax Notoginseng } - Else if(num== (Numeverybit[1]*10+numeverybit[0]) * (numeverybit[2]*10+numeverybit[3])){ the return true; + } A Else if(num== (Numeverybit[1]*10+numeverybit[0]) * (numeverybit[3]*10+numeverybit[2])){ the return true; + } - $ Else if(num== (numeverybit[0]*10+numeverybit[2]) * (numeverybit[1]*10+numeverybit[3])){ $ return true; - } - Else if(num== (numeverybit[0]*10+numeverybit[2]) * (numeverybit[3]*10+numeverybit[1])){ the return true; - }Wuyi Else if(num== (Numeverybit[2]*10+numeverybit[0]) * (numeverybit[1]*10+numeverybit[3])){ the return true; - } Wu Else if(num== (Numeverybit[2]*10+numeverybit[0]) * (numeverybit[3]*10+numeverybit[1])){ - return true; About } $ - Else if(num== (Numeverybit[0]*10+numeverybit[3]) * (numeverybit[1]*10+numeverybit[2])){ - return true; - } A Else if(num== (Numeverybit[0]*10+numeverybit[3]) * (numeverybit[2]*10+numeverybit[1])){ + return true; the } - Else if(num== (Numeverybit[3]*10+numeverybit[0]) * (numeverybit[1]*10+numeverybit[2])){ $ return true; the } the Else if(num== (Numeverybit[3]*10+numeverybit[0]) * (numeverybit[2]*10+numeverybit[1])){ the return true; the } - Else{ in return false; the } the } About } the}