Java Programming Idea--vampire number problem

Source: Internet
Author: User

Vampire numbers: What I started thinking is to take four digits apart, then free to combine and then multiply, and finally compare to get results, in the Internet to see some of the practice of friends, let me surprised Ah, think of their algorithm also want to look, this way down is no drop

Now post the code:

Package Edu.cqu.main;import java.util.arrays;/** * Problem Description: * Vampire numbers are digits with even numbers that can be multiplied by a pair of numbers, which each contain a number of half-digits of the product, * where The number selected in the initial number can be sorted arbitrarily. * For example: * 1260 = 21 * 60 1827 = 21 * 87 2187 = 27 * 81 * requires the output of all four-digit vampire numbers.  * * @author Gabby * */public class Vampirenumber {public static void main (string[] args) {for (int i = 1; i < 100;                    i++) {for (int j = i+1; J <; J + +) {//only require output four-bit number if (i * j >= 1000) {                    String a = i + "" + j;                    String B = i * j + "";                        if (equal (A, B)) {System.out.printf ("%d *%d =%d", I, J, I*j);                    System.out.println ();         }}}}}//Determine if two strings contain the same number as private static Boolean equal (string A, string b) {        First sort char[] as = A.tochararray ();        char[] bs = B.tochararray (); Arrays.sort (AS); Sort Arrays.sort (BS); Sort if (arrays.equALS (AS, BS)) {return true;    } return false; }}

  

Java Programming Idea--vampire number problem

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.