wsoethe
BAN USERpublic class SumOfFirstThreeSameAsLastThree {
public static void main(String[] args) {
for (int i = 0; i < 999999; i++)
if (checkSum(i))
System.out.println(i);
}
public static boolean checkSum(int n) {
// only 6 digits or more
if (n < 100000)
return false;
int begin = n / 1000, last = n % 1000;
// if the begin or last numbers are zero, there is no point to have a sum
if (begin == 0 || last == 0)
return false;
int sum1 = 0, sum2 = 0;
while (begin != 0 || last != 0) {
sum1 += begin % 10;
begin = begin / 10;
sum2 += last % 10;
last = last / 10;
}
return sum1 == sum2;
}
}
- wsoethe March 23, 2010
this is the solution not only for the intergers but also for double values (using cents)
}
- wsoethe March 25, 2010Result:
$1,234,567.99