- #1
Poisonous
- 26
- 0
Homework Statement
The question is thus:
e = even digit
o = odd digit
eo
x ee
-----
eoe
+eoe
-----
oooe
Which is just the expanded multiplication of the numbers eo and ee, with eoe and eoe being the partial products and oooe being the product. The question is to find the numbers which fit the digits.
The Attempt at a Solution
Here is the code I wrote to find the solution:
Code:
public class EvensOdds
{
public static void main(String[ ] args)
{
// num = AB, CD, EFGH
double a, b, c, d, e, f, g, h;
double fir, sec;
double fira, firb, firc;
double seca, secb, secc;
double product;
for(int i = 9; i < 100; i++){
b = Math.floor(i % 10);
a = Math.floor((i % 100)/10);
if(a % 2 == 0 && b % 2 != 0){
for(int x = 9; x < 100; x++){
d = Math.floor(x % 10);
c = Math.floor((x % 100)/10);
if(c % 2 == 0 && d % 2 ==0){
fir = d * i;
firc = Math.floor(fir % 10);
firb = Math.floor((fir % 100)/10);
fira = Math.floor((fir % 1000) / 100);
sec = c * i * 10;
secc = Math.floor(sec % 10);
secb = Math.floor((sec % 100)/10);
seca = Math.floor((sec % 1000) / 100);
if(firc%2==0 && firb%2!=0 && fira%2==0 && secc%2==0 && secb%2!=0 && seca%2==0 && sec < 1000){
product = i * x;
if(product > 999 && product < 10000){
h = Math.floor(product % 10);
g = Math.floor((product % 100)/10);
f = Math.floor((product % 1000) / 100);
e = Math.floor((product % 10000) / 1000);
if(e%2!=0 && f%2!=0 && g%2!=0 && h%2==0){
System.out.println(i+", "+x+", "+fir+", "+sec+", "+product);}}}}}}}
}
}
The code compiles without error, and, to my understanding, should produce the correct answer. But, when I run the program, no solution is printed. If you see an error with my code, or another method to solve the problem please let me know!
Last edited: