|
本帖最后由 jh2009 于 19.9.2009 22:00 编辑
A、B、C三人年龄未知。A年龄数字个位和十位的位置对调一下就是B的年龄;C的年龄两倍是A与B两个年龄之差;B的年龄是C的十倍。问:A、B、C三人的年龄各是多少?
public class Ages {
private int x, y;
private static Ages INSTANCE = null;
private Ages(){
//Nothing to do
}
public static Ages getInstance(){
if (INSTANCE==null){
INSTANCE = new Ages();
}
return INSTANCE;
}
private double ageA() {
return 10 * x + y;
}
private double ageB() {
return 10 * y + x;
}
private double ageC() {
return ageB() / 10;
}
public boolean condition() {
boolean condition = (2 * ageC() == ageA() - ageB()) || (2 * ageC() == ageB() - ageA());
return condition;
}
private void computeAges() {
for (x = 1; x < 9; x++) {
for (y = 1; y < 9; y++) {
if (condition()) {
System.out.println("Result:");
System.out.println("A=" + ageA());
System.out.println("B=" + ageB());
System.out.println("C=" + ageC());
}
}
}
}
public static void main(String[] args) {
Ages.getInstance().computeAges();
}
} |
评分
-
1
查看全部评分
-
|