一、 程序的结构:

一般来说程序的结构包含有下面三种:

1、顺序结构
2、选择结构
3、循环结构

二、顺序结构

程序至上而下逐行执行,一条语句执行完之后继续执行下一条语句,一直到程序的末尾

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAACECAIAAADwRmJLAAAI80lEQVR4nO2dP2jbTBiHb0whg8eOGd2mFA0OGLpoLHTxVAKlREupR28xHerRo6fiIYPo5NFDKR1FJtGhmBKCCSWYDMFDBhNCEaUEfYO+T5/+nhTfq5N0+j2TLcen9957nztJji3mAtBgWNkBAFAm/wtgWdZ4PB7VgfF4bFlWEenQNI0phKZpRWRJJZjruqvVqtvt6ro+HA7Lru1cDIdDXde73e5qtSJOB1NqSVSsO0XAHMfRNM227bIjeTC2bWua5jgOYZuKVYxi3SkCNp1O+/1+2WFsSb/fn06nhA0qVjGKdacIGHkNyYTcXsUqRrHuFAEzDMM0zbLD2BLTNA3DIGxQsYpRrDtFUHsB3rx5s9lsNpvN379/xRtUrGIYY5sAd3d3ZUdUOSQJECksqjozTfPVq1eWZVmWdXp6en19LdigHAGkacYYswIsFgs5+60RNAIkXoSO/EHiY0GCAnjc3t7mf/t6vY5sEYwt7Xp85i4Kyg8EyIRsBeAPYfxVkmGOC3BxcZH/7aPRSNO0+XyeGKcgaU3xJYkLIxgDBOAjQwC/4iOjKz7Spmm+ePFiEuDk5MTKjWEY/iemnga0xZe/y8FJAQLIpEABgrOaG9OAZKozTfPRo0dpc+pD8f4PQiSexFqP5yGegTySbBcPBOAj4xyApUxvJAI8ffr0KMD79+/z/0uFrut+tL1eb7FYUAkQrHU3vdcQoHSkHgK5BawAkXOAB43xaDTySz8x8ocSSUJiNyFApZB3ElzQCiAiwLdv3yJ/TyJA4gIYfIpDoOpAdgjEeermq4wtEBQgjnhI23kOAcqCQIC0cuc8rcghUBza4svTTZI8cBqHAHxq/68QlRWgCkCATCBACAjQNNh4PB4Oh2WHsSXHx8fv3r2DAGlAgEzYcrkk/16VHBzH2d/f//z5Mw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="167" />

三、选择结构

选择结构是根据条件的成立与否,再决定要执行哪些语句的一种结构
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANcAAACeCAIAAAAuSAhGAAAK4UlEQVR4nO2dP2gT7x/Hn0k7qAQFzaAQt06SoUMHlSoKWSpBRERROklAhwiCggGzFUG4SQp1cMwUAgUJTkFEsliSTjVTCB1C6NBCKaGUct/hfr/j8f4890nyPHfPPX2/Brl6l+dfXnk/d5e7HLNTwtLSEmOs3+8n3RAgH5Z0A6jAQoOBhSB5YCFIHlgIkgcWguSBhSB5UmBhp9NptVr5fJ4xVqvVWq3WeDxOulFAJimw0LIsxpHP55NuEZBMCiwcj8fZbNa1sNFoJN0iIJkUWGhzcYggNJJ0WOjGIYLQSNJhoW3blmUhCE0lHRY2m83Xr1/fvXv327dvw+Ew6eYAyehrYb/fX1tbKxaLc3NzhULBsqxarbayspLNZvP5/Pv379vtdtJtBHLQzsJms1kul+fn53O5XKlUajQa/rODnU5ndXV1cXExk8k8efIEAZl2tLDQH3vb29uUF+7t7SEgDSBJCymxRwcBmV7itnDq2KNjUkA631saQ9hZjpgslBt7dNIekIxpscski7DuKOxkDLFHJ6UBCQunJKnYo5OigISFE6BV7NHRPyBhYQTj8Vj/2KOjZ0DCwmC2t7ctyyoUChPFXmD1xP90Dq8orxVvQ3xHtQpI8yzs/8vx8bFNtHA8HjcajVKplMvl5ufny+Vys9kk1hq2ELbMLwT651kr3iasaiKJB2RsFsZTEWOs9S/O5Cmqm4+9YrG4trY2xW0fvAoeIfwW8lYJxoUScuIPwKTEFpCdTof/c3Y5wk7dRdYSlhczNoZk4dSxF1m9/8/ILBQURdzMDnobpu6Fg9KAZIwVi0XXRbkRRZxYPAMlZdDcokQWSom9sIr9fQu0UIy7meclgkr920vpkUtgQLZarY8z4PbXcVG6hf6Povhj7B/GGRsQamG5XGaMZTIZy7KkVBZYvf/PwLEQLPAbCz6pYQMn3UIe9y5B/hYZKczYMMogB9ZIMXWKxoiyUPU5F6KF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j3u9b+l0zdGF7BHz9+dLvd2YvVGVhILU1gKpvw17AjG+D69+rVq4sXL3748GHGMjUHFgaU5g82gZrSG8MYc/1zmnH79u2PRuN8+3XaLQwUzrMQOFl7XihrRs5ms2HRazCwUM6zn2Q1pl6vP3r06MyZM05LjM9ChwSvY9fLQjv8SRNxWujsF7ouGr9fmDgaWegxz2+hX1BxZE7dGP4YuV6v//z5c8YygRgtLLSn9YnX0R+fU7fktJ0vTBxdLORLoygly7nAkmFhzGhnYeLAwviBhV5gYfzAQi+wMH5goRdYGD+w0AssjB88gczLKXwCWeLgSRPRwELVwMJoYKFqYGE0sFA1sDAaWKgaJRYOh8OObBYWFhhj379/l15yJEdHRypGCbik5iQLfsvVYGAhSB5YCJIHFoLkgYUgeWAhSB5YCJIHFoLkgYUgeVJg4erq6tLSknP92OLiYqFQwFdqhpECCzudDn/9X7lcTrpFQDIpsNC27WKx6Cg4Nzc3HA6Tbg6QTDosdOMQQWgk6bDQtu1isYggNJXUWNjpdBCEppIaC23bxqGxqaTJQmAq/wFSJLI9OjWMlAAAAABJRU5ErkJggg==" alt="" width="245" height="180" />

3.1 、IF语句--单分支结构

if (判断条件){
语句1 ;
语句2 ;
}
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANYAAACHCAIAAADlUzArAAAJ2UlEQVR4nO2dP2jbTByGb2uHthgKbYYW3M1T0dChQwpuaSFLiulQSkuLp+KhgwuFdjA4WykUNJVAOnT0FAxZPGoqXhqcTK4nYTIEkyGBEEQJQd9wfOKsP6ef7JNOUt5nCHJ0Op3Oj96TJctibhGo1+uMMdu2dTcEqIfpbgAJKFhioCDQDBQEmoGCQDNQEGgGCgLNQEGgGSgINAMFgWbyruBoNLIsyzAMxliv17Msy3Ec3Y0CKsm7gqZpMgHDMHS3CCgm7wo6jrOysuIp2O/3dbcIKCbvCrpCECICS0kBFPSCEBFYSgqgoOu6pmkiAstKARQcDAYfPnx48uTJr1+/Dg8PdTcHKCanCtq2vbm52Wg0rl69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6CHE/EOo4FC05RFeTYtp3e0xtBNhRbQVACoCDQDBQEmoGCQDNQEGgGCgLN5F3Bzc3NbrdbrVYZY+12u9vtFuUZi4BI3hU0TVO8jtRoNHS3CCgm7wo6jrOysuIpqPE6EkiJvCvoCkGICCwlBVDQC0JEYCkpgIKu65qmiQgsK8sqyB/HUBoMw1DSrYDOsgqycv04Wsk2pxBAwTlKtjmFAArOUbLNKQRQcI6SbU4hgIJzlGxzCgEUnIMxFvrMXJAeWSsolg9dlgm/Gp1Nk3zL+m6zxbci0kabgqGqyQWNOpkX2x56I6Fg9mSqIFEg8W/S9VI0lVcLBTNGQwpKtPApKLEntB5JYXrzoGDG6B+IxVnB6Iodpn0ToeEHBfNMXlIwOARLFBRtiyoTLE9sHhTMGP0pGJQmaiD2TUtUlqwitnlQMGOyUzB0kI3NwtC5kuM/DMSFQ+d5waiXscEmUXDJRkLB7Mk6BYm1hYZZsLbYOikr9ZWHghmDC3RzQMHsgYJzQMHsgYJzQMHsgYJzQMHsWVagSqXCSsS1a9egYMaozzDbti11bGxsWJbF79Nrt9sb/xNaUjLXV4zeACiYNnlXkMMV7PV6ymuOBQqmDRSMAQqmDRSMAQqmDRSMAQqmjXoFHcc5Vs3q6ipjbH9/X3nNsVxcXCjvIiBSjLN6+KHfEgMFgWagINAMFASagYJAM1AQaAYKAs1AQaCZvCs4Go18V0dwuaJk5F1B39OX8HPk5SPvCvqevtTv93W3CCgm7wq6QhAiAktJART0ghARWEoKoKDruqZpIgLLSjEUdBzHsizdrQCpUAwFQYmBgkAz/wEEIuDgic4lOAAAAABJRU5ErkJggg==" alt="" />

示例一、 比较2个整型变量的大小

package pb.test;

public class test4 {

    public static void main(String[] args) {
int x = 3;
int y = 10; //定义2个整型变量,x,y
System.out.println("=======开始比较=======");
if(x>y){
System.out.println("x比y大!");
}
if(x<y){
System.out.println("x小于y!");
}
if(x==y){
System.out.println("x等于y!");
}
System.out.println("=======比较完成======="); } }

3.2、if...else语句--双分支结构

if (判断条件){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5n7/WXcTYga+JcgMtYdCvAvQWSsOxTgX4LIWHcowL8EkbHuUIB/CYIxht8fRUYM/jHVn0Y6H05s9jSrBMP/D0VInP55eia30++knbI99EYK/v38+bPb7RLnTSkz5B/RHv41aL0UR+XFOua9evXq4sWLHz58IM6bUmbIP0v1F9CCfxJ1PMuRTExvnmOeXfjt27c/Zhr7CtYM+ec3o2do+enlLkewllczkH/5fN4vRDPMDPnn4C7H71Woi3Gq+U3jnp7YvEaj8ejRozNnztjlZz7/bGK5tzwR+ec2hp1OMs+65B5LqlA2z97/cyzM/P5fjETqnxD4FhdgQmnuVBPG+knpWUvQRvLHv41G49evX8R5QVBiPv/n91YZaRL/pmwkm73zfzESQ/4RS/OMMXdpyjIplQrTw7/IwPU3EfgXJfBPBP5FCfwTgX9RAv9E4F+UwD8R+BclIaiD52+BidESXX08fwHQgH9q4J8+4J8a+KcP+KcG/ulDi3/D4bATNgsLC4yxHz9+hF6ykqOjIx1LCVia/NMB/v80k8A/ECfwD8QJ/ANxAv9AnMA/ECfwD8QJ/ANxAv9AnKTAv9XV1aWlJfsur8XFxVKphAtimSEF/nU6Hf7+vGq1GneLQGikwD/Lssrlsi3f3NzccDiMuzkgNNLhnxOBCL+MkQ7/LMsql8sIv+yRGv86nQ7CL3ukxj/LsnDYmz3+A2tUTdrAmUL2AAAAAElFTkSuQmCC" alt="" />

示例二、判断一个数字是奇数还是偶数

package pb.test;

public class test5 {

    public static void main(String[] args) {
int x=3; //定义大中型变量x
if(x%2==0){ //如果余数为0则是偶数
System.out.println("x是偶数");
}else{ //如果余数不为0则是奇数
System.out.println("x是奇数");
} } }

3.3、三目运算符

使用三目运算符时,操作数有3个,其格式如下:
变量 = 条件判断?表达式1:表达式2
根据条件的成立与否,来决定结果为“:”前或“:”后的表达式,如果条件判断为true,则执行表达式1,为false则执行表达式2

示例三、求出2个数字中的最大值

public static void main(String[] args) {
//定义变量来保存最大值
int max=0;
//定义2个变量
int x=3;
int y=10;
//使用3目运算判断如果x>y则,max=x,否则max=y;
max=x>y?x:y;
System.out.println("max为: "+max); }

3.4、if…else if…else语句 --多分支结构

如果需要在if..else里判断多个条件时,就需要if..else if … else语句了,其格式如下:
if (条件判断1){
语句主体1 ;
}else if (条件判断2){
语句主体 2 ;
}
… // 多个else if()语句
else{
语句主体3 ;
}

示例四、

package pb.test;

public class test6 {

    public static void main(String[] args) {
int x=3;
if(x==1){
System.out.println("x的值是1!");
}else if(x==2){
System.out.println("x的值是2!");
}else if(x==3){
System.out.println("x的值是3!");
}else{
System.out.println("x的值不是1,2,3 中的一个!");
} } }

四、Switch结构

要在许多的选择条件中找到并执行其中一个符合判断条件的语句时,除了可以使用if..else不断地判断之外,也可以使用另一种更方便的方式即多重选择——switch语句,语法格式:
switch (表达式){
case 选择值1 : 语句主体 1 ;        break ;
case 选择值2 : 语句主体 2 ;                 break ;
…….
case 选择值n : 语句主体 n ;                break ; default:  语句主体 ;
}

4.1、执行流程

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaUAAADaCAIAAACJs8pZAAAUaElEQVR4nO2dvWtb1xvHTxqXCiocFUIRWeKhQ4YQ7mBChg7eagikakggm7UYZ9SUZAnSlm76Azxk6KChg4bgWYQMpnTQUIqGUoSGooIxxpgiigf9hlvu7+q+nHvueX/5foYiS/ec+zzPOfejx1dqTNYAKKbb7RJCJpOJ6UBA6BDTAQD/ge+AJcB3QDnwHbAE+A4oZDgckhSNRmO5XJoOCoQLfAcUslqt2u124rter2c6IhA08B1QS9LiobkDxoHvgFqSFg/NHTAOfAeUMxwO0dwBG4DvgHI+fvz47Nkz+A4YB74DSlgul+/fv3/x4kWr1Xr06FG3222321EUvXnz5vT01HR0IFDgOyCT09PTN2/eRFHUbre73e5oNLq4uEhenU6n7969e/ToUavVevHixfv379H0AZ3Ad0CUTCv37t276XRKH3JxcTEajdD0Ac3Ad4CT6XTa7/fLWrla86SbPu55AKgEvgM1yPRl/X6/spWrO3mtPhGAWsB3oBr9993o9wEB4AO+A8VYc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f7hJBJYP0F8Iz5fE4I2dvbMx2Ik3S7XbMSgO8AqAF8JwJ8B4BLwHciwHcAuAR8JwJ8B4BLwHciwHcAuAR8J0JwvouiaA8ERrPZ3NraunXrVst9tre3CSGtVst0UZ2k3W6H5TsAQOAE4bu5gq9rAye4efMmIUTwnzmwimlgX9v2Bq/+vTBgJ1tbW4SQn3/+2XQgIHTgO6Ac+A5YAnwHlAPfAUuA74By4DtgCfAdUA58BywBvgMK+e677+7evXvjxg1CyNdff3337t2///7bdFAgXOA7oJCnT5+mv3jVaDRMRwSCBr4Davnss88S3/3444+mwwFBA98BtSQtHpo7YBz4DignbvHQ3AHjwHdAOU+fPkVzB2wAvguaKIq0/B/imoiiyHRFgdXAd0FDiFcbwLN0gHSwP4LGM0F4lg6QDvZH0HgmCM/SAdLB/ggazwThWTpAOtgfQeOZIDxLB0gH+yNoPBMEISTzDxGbjgjYhVfbHdSlru/SxxeOTZ7kNqmIguE7QAe+Cxpu3xV6jW7Dsi/NVcbDHiR8B+jAd0FTy3eMtkr/t+55WZxInxa+AxTgu6Dh6O8oDsr4jqKqwnkoB7OHB98BCvBd0Ij/Ppt+Kd+UVf62m3lQ2NbBd0AW8F3QyOrv8r/JUnyXVlvZMfnjGcOD7wAF+C5oxPu7vKHKfp/NPKZ4k3KKyvDgO0ABvguaWirJ/65a2eUVvkq5Z4ffZ4FS4Lug4e7vKD9WtmwU3wkGCd8BOvBd0NTt7xhnK2zT8rNVzsly0szx8B2gAN8FTd3+znLgO0DHq+0O6gLfgaDwaruDusB3ICi82u6gLvAdCAqvtjuoS6vVIh7RbDbhO0ABvgMbzGazCRuDwWAwGFQekz44oWy2yjlZTprGdDmBXcB3YAN23zmB6XICu4DvwAbwHfAY+A5sAN8Bj4HvwAbwHfAY+A5s8M8//1x4hOlyAruA7wAAoQDfAQBC4X+D0rvUo3vhZwAAAABJRU5ErkJggg==" alt="" />

示例五、判断学生成绩,并给于评分,90~100分,A级大于80分,B级,大于70分,输出C级,大于60分,D级,低于60分输出E级

package pb.test;

public class test7 {

    public static void main(String[] args) {
int score = 75; //声明学生分数
switch (score/10){
case 10:
case 9:
System.out.println("A级");
break;
case 8:
System.out.println("B级");
break;
case 7:
System.out.println("C级");
break;
case 6:
System.out.println("D级");
break;
default:
System.out.println("E级");
break;
} } }

结果:C级

还是上面的如果不加break;

package pb.test;

public class test7 {

    public static void main(String[] args) {
int score = 75; //声明学生分数
switch (score/10){
case 10:
case 9:
System.out.println("A级"); case 8:
System.out.println("B级"); case 7:
System.out.println("C级"); case 6:
System.out.println("D级"); default:
System.out.println("E级"); } } }

结果:C级,D级,E级

Java从零开始学七(选择结构)的更多相关文章

  1. Java从零开始学八(循环结构)

    一.循环结构 循环结构则是根据判断条件的成立与否,决定程序段落的执行次数,而这个程序段落就称为循环主体.

  2. 038 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 05 案例演示switch结构-星期的表示案例以及总结

    038 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 05 案例演示switch结构-星期的表示案例以及总结 本文知识点:案例演示switch结构并对sw ...

  3. 034 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 01 流程控制概述

    034 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 01 流程控制概述 本文知识点:Java中的流程控制相关概念的认识 三大流程控制语句结构的简介 顺序 ...

  4. Java 第三章 选择结构1

    选择结构(一) 会使用基本的 if 选择结构 掌握逻辑运算符,掌握多重 if 选择结构 , 掌握嵌套 if 选择 结构 为什么需要 if 选择结构 例如: 如果张浩的 java 考试成绩大于 98分, ...

  5. 037 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 04 switch结构

    037 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 04 switch结构 本文知识点:Java中的switch结构 选择结构分类 选择结构只有如下2种 ...

  6. 036 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 03 嵌套if结构

    036 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 03 嵌套if结构 本文知识点:Java中的嵌套if结构 什么是嵌套if结构? 概念: 嵌套if结构 ...

  7. 035 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 02 多重if结构

    035 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 02 多重if结构 本文知识点:Java中的多重if结构 选择结构回顾 if选择结构 注意: 1.条 ...

  8. java中的if-Switch选择结构

    字随笔走,笔随心走,随笔,随心.纯属个人学习分析总结,如有观者还请不啬领教. 1.if选择结构 什么是if结构:if选择结构是根据判断结果再做处理的一种语法结构. 起语法是: if(判断条件){ 操作 ...

  9. 小白的java学习之路 “ 选择结构(一)”

    if选择结构: if选择结构是根据条件判断之后再做处理的一种语法结构. 1.if选择结构的语法: public class Demo{ public static void main(String[] ...

随机推荐

  1. spring---transaction(1)---源代码分析(事务的拦截器TransactionInterceptor)

    写在前面: 先了解一下spring的事务.分为分明式事务管理和注解式事务管理,对于前期的事务,spring会通过扫描拦截对于事务的方法进行增强(以后讲解). 若果目标方法存在事务,spring产出的b ...

  2. Maven项目META-INF文件夹不存在的问题

    直接在resources文件夹下新建META-INF文件夹即可. 参考: https://my.oschina.net/KingPan/blog/750159 https://stackoverflo ...

  3. Linux服务器压测/拷机软件收集

    最近公司采购了一批服务器,于是收集了一些拷机软件来压测服务器硬件性能.硬件的稳定相对来说比较重要,7x24小时无间断运行,主要看三个硬件:CPU.内存.硬盘. 下面是收集的一些教程,可能网址已经失效了 ...

  4. Design Pattern Singleton 单一模式

    单一模式的几个注意点: 一) 设计单一模式,首先须要把构造函数给私有化了,不让外界訪问,那么外界仅仅能通过提供的函数获取一个新的类. 二) C++的单一模式,记得要在类外初始化一个类,否则或内存出错的 ...

  5. 基于tomcat7 web开发中的一点小东西

    控制台: org.apache.jasper.compiler.TldLocationsCache tldScanJar 信息: At least one JAR was scanned for TL ...

  6. hue解决timed out(code THRIFTSOCKET):None

    报错栈: Traceback (most recent call last): File , in decorator return func(*args, **kwargs) File , in e ...

  7. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 总结

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序  总结         SP2013新的server端Off ...

  8. Objective-C:NSMutableString类的常见操作

    NSMutableString可变字符串的主要的操作是创建.增加.删除.插入.替换 代码操作如下: // // main.m // 03-NSMutableString // // Created b ...

  9. hdu 1242 Rescue(BFS入门)

    第一次用容器做的BFS题目,题目有个地方比较坑,就是遍历时的方向,比如上下左右能AC,右上左下就WA #include <stdio.h> #include <string.h> ...

  10. otl中遇到的一些字符数组长度问题

    最近做的项目中对于数据库的操作为了有一个统一的操作,所以采用了otl技术作为中间媒介,当然,由于是用了别人的库,所以还是出现了很多问题.通过对问题进行分析,也形成了一些常用问题的处理方法. 在用otl ...