"Java Programming Idea-practice" vampire numbers

Source: Internet
Author: User

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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.