
上QQ阅读APP看书,第一时间看更新
4-11程序语句的结合与分行
4-11-1 语句的结合
在Java程序设计时,语法是允许将两行语句结合为一行,只要彼此间用“;”隔开即可。例如,有两条语句如下。
x=5;
y=10;
也可写成:
x=5; y=10;
程序实例ch4_49.java:表达式结合为一行的应用。下列程序第4行是由两条语句组成。

执行结果

4-11-2 语句的分行
在Java中如果语句很长想用两行表达,除了字符串中间不能随便分行外,建议在运算符后方执行分行。
程序实例ch4_50.java:这个程序基本上是重新设计ch3_11.java,但是原先3~6行分别采用不同的分行。

执行结果
与ch3_11.java相同。
上述程序第4行是“,”前方分行,第6和8行是在“,”后方分行。