日期:2014-05-20 浏览次数:20932 次
public class Testcup {
String d;
int w;
static String Test1(String d) {
if (d == "塑料的") {// 邏輯判斷用“==”符,(String d ="塑料的")是一個賦值語句,if語句只接受true或false或者邏輯表達式
String r = "Yes";
return r;
} else if (d == "玻璃的") {// 同上
String r = "No";
return r;
} else {
String r = "Er";
return r;
}
}
static String Test2(int w) {
if (w < 10) {
String o = "Yes";// String錯寫為Srting了
return o;
} else {
String o = "Heavy";
return o;
}
}
public static void main(String[] args) {
Testcup e = new Testcup();
e.d = "塑料的";
e.w = 9;
if (Test1(e.d) == Test2(e.w)) {
System.out.println("This one is required");
} else {
System.out.println("I'm sorry , this one is not required");
}
}
}
------解决方案--------------------