Lab environment:jdk1.8.0_111
Process Control in the Java language
• Select structure
1,if-else statements
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/B5/wKioL1g472ah061sAAFLo4-VqBI227.png "title=" Zi3mc0td9dhv7izcujecewb.png "alt=" Wkiol1g472ah061saaflo4-vqbi227.png "/>
When using If,else If,else, the following block of statements is enclosed in {}:
If and else pair use
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8A/B5/wKioL1g48dKzvqkTAAA6SDfaMBE793.png "title=" o_014_ 5mn89d]p0g) [r3i8j.png "alt=" Wkiol1g48dkzvqktaaa6sdfambe793.png "/>
If...else the difference between If...else and If...if...if:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/B9/wKiom1g48z6ikV6aAAAfo7e12Ks820.png "title=" 9A ') {7 (ER ' Slv9[_p_ ([tky.png "alt=" Wkiom1g48z6ikv6aaaafo7e12ks820.png "/>
It is known that the former indicates that the program may have an entrance and that there may be an exit, which is bound to be exported in the case of an else clause.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8A/B9/wKiom1g49CrjaFGyAAAlKVZrifA154.png "title=" C (SQ] Gt@c8do3 ' Je9~lb$ma.png "alt=" Wkiom1g49crjafgyaaalkvzrifa154.png "/>
Known, the latter indicates that the program may have multiple entrances.
Practice
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8A/B5/wKioL1g49JeDUA2DAAFnDxrKICw585.png "title=" UI) { 3c26564569~aymvim6o.png "alt=" Wkiol1g49jedua2daafndxrkicw585.png "/>
How to implement a three integer input by the keyboard:
---Import the scanner class outside the class keyword
Import Java.util.Scanner;
Create a Scanner object
Scanner Scanner = new Scanner (system.in);
, get input integer
System.out.print ("NUM1 ="),//print without ln means that the output does not wrap
int i = Scanner.nextint ();//means input an integer
System.out.println ("Output NUM1 is" + NUM1);//This means that the string is added
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/8A/B5/wKioL1g4-5ijvXDyAABW6ovPajk035.png "title=" 56p]rz [~@)) 7l0y2 (ybx49t.png "alt=" Wkiol1g4-5ijvxdyaabw6ovpajk035.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8A/BA/wKiom1g4-9OScLr5AAGHHucAN9k684.png "title=" B35i6] s1v1}b{) Zeb ' $A 2jw.png "alt=" Wkiom1g4-9osclr5aaghhucan9k684.png "/>
Known output as x Is2
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8A/BA/wKiom1g4_R6QEl3-AAAXQ6SofM4281.png " title= "$J 4v29xli8p~%6tns2[799p.png" alt= "Wkiom1g4_r6qel3-aaaxq6sofm4281.png"/>
2,switch statements
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8A/B5/wKioL1g4_VigGXohAAFUp9f_aKA842.png "title=" 32@k$$ {7a3lq2f (NX@QEPZO.png "alt=" Wkiol1g4_viggxohaafup9f_aka842.png "/>
The switch statement indicates the meaning of the switches, with the following rules for the switching statement:
->switch (expression), the return value of an expression must be one of the following 6 data types
Byte,short,int,char (JDK1.4)
Enumeration type (JDK5.0 added)
String (JDK7.0 added)
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8A/B6/wKioL1g4_5nDjeCXAAApZc5CkD4352.png "title=" TC)] urepop~x8[}gv@ ' D$}b.png "alt=" Wkiol1g4_5ndjecxaaapzc5ckd4352.png "/>
The value in the->CASE clause must be a constant, and the value of all case clauses should be different
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/B6/wKioL1g5AIfwhZMTAAAmbn6iFKE604.png "title=" {) $ Ujfqge4dbv]xm59l@0gk.png "alt=" Wkiol1g5aifwhzmtaaambn6ifke604.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/8A/B6/wKioL1g5APOwXrd_AAAZVLyLRkA115.png "title=" tsbu5@l) 1[yff9r]4p}{t9j.png "alt=" Wkiol1g5apowxrd_aaazvlylrka115.png "/>
The->DEFAULT clause is optional and dispensable
Equivalent to the ELSE clause in the IF-ELSE statement
->break statement that executes a case branch, causes the program to jump out of the switch statement block
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8A/B6/wKioL1g5BOCRv4nSAAAXg_FENnI868.png "title=" 6yhv7n {]g) p]}dkm@wv_m]t.png "alt=" Wkiol1g5bocrv4nsaaaxg_fenni868.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8A/B6/wKioL1g5BSShHB5BAAAZMKtoM-w235.png "title=" 09u7e_ 52X (OHA (2pbb{m~gm.png "alt=" Wkiol1g5bsshhb5baaazmktom-w235.png "/>
Practice
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8A/BA/wKiom1g5BU_gmbjnAAE5K25scLE296.png "title=" 36v5{ Bga439gz73c{ekt2io.png "alt=" Wkiom1g5bu_gmbjnaae5k25scle296.png "/>
class TestSwitch{ public static void main () { int a = 3; int x = 100; switch (a) { case 1: x += 5; break; case 2: x += 10; break; case 3: x += 16; break; case 4: x += 34; break; default: x += 100; break; } } }
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/8A/B6/wKioL1g5BsuzcgqGAAHt64pT-KM228.png "title=" GFF5V44}N~WJRL (O8$0{w (q.png "alt=" Wkiol1g5bsuzcgqgaaht64pt-km228.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8A/B6/wKioL1g5CbiwQqqXAABZZRm0u8Q520.png "title=" ~FARQM ~h ' e5$su2bxl%$ @JP. png "alt=" Wkiol1g5cbiwqqqxaabzzrm0u8q520.png "/>
This article is from the "Novice Technical Documents" blog, please be sure to keep this source http://zhubo.blog.51cto.com/11395641/1876825
Process Control in the Java language