Java. In a positive integer less than 99999, find the number that meets the following criteria, which is both full squared and two digits the same, for example: 144,676.

Source: Internet
Author: User

Label:

1 ImportJava.util.HashMap;2 ImportJava.util.Map;3 ImportJava.util.Map.Entry;4 //in a positive integer less than 99999, find the number that meets the following criteria, which is both a full square number,5 //another two digits are the same, such as: 144,676. 6  Public classWQS {7     8     //Total Square Number9      Public Static BooleanIswqs (intN) {Ten         inti; One         Doubledn=math.sqrt (n); A         if(Dn-(int) dn==0) -             return true; -         return false; the     } -     //Judging only two bits of the same -      Public Static BooleanTwosame (intN) { -map<integer,integer>map=NewHashmap<integer,integer>(); +          while(n>0){ -             intN1=n%10; + //System.out.print (N1); A             if(Map.containskey (N1)) at             { -                 intVal=Map.get (N1); -Map.put (n1,val+1); -             } -             Else -Map.put (N1, 1); inN=n/10; -         } to //System.out.print (map); +          for(entry<integer,integer>En:map.entrySet ()) -         {  the             if(En.getvalue () ==2){ *                 return true; $             }Panax Notoginseng         } -          the         return false; +     } A      the      Public Static voidMain (string[] args) { +     inti; -          for(i=2;i<99999;i++){ $             if(Twosame (i) &&Iswqs (i)) { $System.out.println (i+ ""); -             } -         } the     } - Wuyi}

Java. In a positive integer less than 99999, find the number that meets the following criteria, which is both full squared and two digits the same, for example: 144,676.

Related Article

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.

Tags Index: