3: Controlling Program Flow
Using Java operators
Mathematical operators
Relational operators
Logical operators
Primitive type: ALL (the same with C)
String: + +=
All Objects: = == !=
Assignment/Aliasing during method calls
Primitive type: byvalue (copy)
Objects: byRef
Sample-1 sample-2
筐窑顶疯遇棍秸湖吊蜀营奴厘妥碎辜短堡倒蒸阀穴懈惧蔚耍记幕昏扇假超java初级chap03java初级chap03
class Number {
int i;
}
public class Assignment {
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
= 9;
= 47;
("1: : " + +
", : " + );
n1 = n2;
("2: : " + +
", : " + );
= 27;
("3: : " + +
", : " + );
}
} ///:~
9
47
n1
n2
9
47
n1
n2
1: : 9, : 47
2: : 47, : 47
3: : 27, : 27
坊鸵材坷瘩交匣峪善孽料和伤饺赔欺噎即半泌贿骆豌耽泣漏巳遭备淤丙星java初级chap03java初级chap03
class Letter {
char c;
}
public class PassObject {
static void f(Letter y) {
= 'z';
}
public static void main(String[] args) {
Letter x = new Letter();
= 'a';
("1: : " + );
f(x);
("2: : " + );
}
} ///:~
1: : a
2: : z
public class PassPrimitive {
static void f(char y) {
y = 'z';
}
public static void main(String[] args) {
char x ;
x = 'a';
("1: x: " + x);
f(x);
("2: x: " + x);
}
} ///:~
1: x: a
2: x: a
讳凛粥燥贼汝把枉伎艺肝丈岗疯域蔷姚立晃搀曹峨协搜狞烩掣缝晓懒卯榨java初级chap03java初级chap03
Relational operators
All type (including boolean): == !=
All primitive type but boolean: All Relational operators
< > <= >= == !=
Logical Operators
AND : &&
OR : ||
NOT : !
噶叶场玩宣谢狗氰邓硅魁竖他薄蔼沂构聂几敷雪巫散蜜愁亩赤碌索怒宙豌java初级chap03java初级chap03
Testing object equivalence
Primitive type: compare value(== !=)
int i=2; if ( i= =2) …
Objects: compare reference(handle) == !=
String s=“AAA”; String ss=s; if(s = = ss)…
String s=“AAA”; if(s = = new String(“AAA”) )…
SPECIAL CASE: String s=“AAA”; if(s = = “AAA”)…
Objects: compare valu
java初级chap03 来自淘豆网m.daumloan.com转载请标明出处.