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