Ideas on solving the vampire data

Source: Internet
Author: User

Java programming ideology has the following question:

  • A vampire number refers to a number with an even number, which can be obtained by multiplying a number. These two digits must contain all the numbers of the product (the order can be any sort), and the number that can be divisible by 100 is not allowed:

For example, the following are all vampires:

1260 = 21*60

1827 = 21*81

2187 = 27*81

Let's analyze the question:

The following conditions are provided:

  • The number of all numbers obtained by multiplying two digits and containing the product indicates that the product must be 4 bits (the range must be between 1000 and 9999)
  • Cannot be divisible by 100

Since the two digits are multiplied, the range is limited to: 10 ~ 99. All numbers that must contain the product must be the same as the two logarithm. here we can use Arrays for comparison.

Let's take a look at the code implementation

Package COM. itheima. test; import Java. util. arrays; public class Mian {public static void main (string [] ARGs) {// todo auto-generated method stub for (INT I = 10; I <100; I ++) {// I indicates the first double digit for (Int J = 10; j <100; j ++) {// J indicates the second double digit int Product = I * j; // obtain the product if (product % 100! = 0 & product> 999 & product <10000) {// filter condition: 1 cannot be divisible by 100. 2 must be 4-digit string [] value1 = string. valueof (product ). split (""); // convert the product to a string, and split it into an array string [] value2 = (string. valueof (I) + String. valueof (j )). split (""); // concatenate two digits into strings, and divide them into arrays by spaces. sort (value1); // sort arrays from small to large. sort (value2); // sort it from small to large if (arrays. equals (value1, value2) {// call the static method equals in arrays to compare system. out. println (I + "*" + J + "=" + product); // print the number of vampires }}}}}}

This is just a simple question.

 

Ideas on solving the vampire data

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.