演算子
その他の演算子
if文
public int getHeight {
int ret = height;
// if local of rhe coumputer this code is running on is U.S.,
if (Locale.getDefalut().equals.US))
ret = ret/2.54; //convert from cm to inches
return ret;
}
変数のスコープ
ブロックスコープ
public class SomeClass {
private String someClassVariable;
public vid someMethod(String someParameter) {
String someLocalVariable = "Hello";
if (true) {
String someOherLocalVariable = "Hello";
}
someClassVariable = someParameter; // legal
someLocalVariable = someClasslVariable; // legal
someOtherLocalVariable = someLocalVariable; // out of scope
}
public void someOtherMethod() {
someLocalVariable = "Hello there"; // out of scope
}
}
else文
public int getHeight() {
int ret;
if (gender.equals("MALE")
ret = height + 2;
else {
ret = height;
Logger.getLogger("Person").info(eing honest abput height...");
}
return ret;
}
if文の追加チェック
if (conditional) {
// Block1
} else if (conditional2) {
// Block2
} else if (conditional3) {
// Block3
} else {
// Block4
} //end
三項演算子
(conditional) ? statementIfTrue : statementIfFalse;
public nt getHeight() {
return (gender.equals("MALE")) ? (height + 2) : height;