当前位置: 首页 > news >正文

个人网站做论坛还是博客好长沙网站优化

个人网站做论坛还是博客好,长沙网站优化,网站换空间有影响吗,怎么用dwcs6做网站设计顺序结构只能顺序执行,不能进行判断和选择,因此需要分支结构。 Java有两种分支结构: if语句switch语句 if语句 一个if语句包含一个布尔表达式和一条或多条语句。 语法 If 语句的用语法如下: if(布尔表达式) {//如果布尔表达…

顺序结构只能顺序执行,不能进行判断和选择,因此需要分支结构。

Java有两种分支结构:

  • if语句
  • switch语句

if语句

一个if语句包含一个布尔表达式和一条或多条语句。

语法

If 语句的用语法如下:

if(布尔表达式)
{//如果布尔表达式为true将执行的语句
}

如果布尔表达式的值为 true,则执行if语句中的代码块。否则执行 If 语句块后面的代码。

public class Test {public static void main(String args[]){int x = 10;if( x < 20 ){System.out.print("这是 if 语句"); }}
} 

以上代码编译运行结果如下:

这是 if 语句

if...else 语句

if 语句后面可以跟 else 语句,当if语句的布尔表达式值为 false 时,else 语句块会被执行。

语法

if…else 的用法如下:

if(布尔表达式){//如果布尔表达式的值为true
}else{//如果布尔表达式的值为false
}

实例

public class Test {public static void main(String args[]){int x = 30;if( x < 20 ){System.out.print("这是 if 语句");}else{System.out.print("这是 else 语句");}}
} 

以上代码编译运行结果如下:

这是 else 语句

if...else if...else 语句

if 语句后面可以跟 else if…else 语句,这种语句可以检测到多种可能的情况。

使用if,else if,else语句的时候,需要注意下面几点:

  • if 语句至多有 1 个 else 语句,else 语句在所有的 else if 语句之后。
  • If 语句可以有若干个 else if 语句,它们必须在 else 语句之前。
  • 一旦其中一个 else if 语句检测为 true,其他的 else if 以及 else 语句都将跳过执行。

语法

if...else 语法格式如下:

if(布尔表达式 1){//如果布尔表达式 1的值为true执行代码
}else if(布尔表达式 2){//如果布尔表达式 2的值为true执行代码
}else if(布尔表达式 3){//如果布尔表达式 3的值为true执行代码
}else {//如果以上布尔表达式都不为true执行代码
}

实例

public class Test {public static void main(String args[]){int x = 30;if( x == 10 ){System.out.print("Value of X is 10");}else if( x == 20 ){System.out.print("Value of X is 20");}else if( x == 30 ){System.out.print("Value of X is 30");}else{System.out.print("这是 else 语句");}}
}

以上代码编译运行结果如下:

Value of X is 30

嵌套的 if…else 语句

使用嵌套的 if-else 语句是合法的。也就是说你可以在另一个 if 或者 else if 语句中使用 if 或者 else if 语句。

语法

嵌套的 if…else 语法格式如下:

if(布尔表达式 1){如果布尔表达式 1的值为true执行代码if(布尔表达式 2){如果布尔表达式 2的值为true执行代码}
}

你可以像 if 语句一样嵌套 else if...else。

实例

public class Test {public static void main(String args[]){int x = 30;int y = 10;if( x == 30 ){if( y == 10 ){System.out.print("X = 30 and Y = 10");}}}
}

以上代码编译运行结果如下:

X = 30 and Y = 10

switch 语句

switch 语句判断一个变量与一系列值中某个值是否相等,每个值称为一个分支。

语法

switch 语法格式如下:

switch(expression){case value ://语句break; //可选case value ://语句break; //可选//你可以有任意数量的case语句default : //可选//语句
}

switch 语句有如下规则:

  • switch 语句中的变量类型只能为 byte、short、int 或者 char。从 Java SE 7 开始,switch 支持字符串 String 类型了,同时 case 标签必须为字符串常量或字面量。
  • switch 语句可以拥有多个 case 语句。每个 case 后面跟一个要比较的值和冒号。
  • case 语句中的值的数据类型必须与变量的数据类型相同,而且只能是常量或者字面常量。
  • 当变量的值与 case 语句的值相等时,那么 case 语句之后的语句开始执行,直到break语句出现才会跳出 switch 语句。
  • 当遇到 break 语句时,switch 语句终止。程序跳转到 switch 语句后面的语句执行。case 语句不必须要包含break 语句。如果没有 break 语句出现,程序会继续执行下一条 case 语句,直到出现 break 语句。
  • switch 语句可以包含一个 default 分支,该分支必须是 switch 语句的最后一个分支。default 在没有 case 语句的值和变量值相等的时候执行。default 分支不需要 break 语句。

实例

public class Test {public static void main(String args[]){//char grade = args[0].charAt(0);char grade = 'C';switch(grade){case 'A' :System.out.println("优秀"); break;case 'B' :case 'C' :System.out.println("良好");break;case 'D' :System.out.println("及格");case 'F' :System.out.println("你需要继续努力");break;default :System.out.println("无效等级");}System.out.println("你的等级是 " + grade);}
}

以上代码编译运行结果如下:

良好
你的等级是 C

文章转载自:
http://embryophyte.tgcw.cn
http://chapelmaster.tgcw.cn
http://descendent.tgcw.cn
http://firing.tgcw.cn
http://seismoscope.tgcw.cn
http://tawie.tgcw.cn
http://autoworker.tgcw.cn
http://habanero.tgcw.cn
http://surfcaster.tgcw.cn
http://sporotrichosis.tgcw.cn
http://avengement.tgcw.cn
http://amuck.tgcw.cn
http://gingerade.tgcw.cn
http://dioptric.tgcw.cn
http://nomadism.tgcw.cn
http://peascod.tgcw.cn
http://removal.tgcw.cn
http://frangipani.tgcw.cn
http://titian.tgcw.cn
http://liveryman.tgcw.cn
http://nascence.tgcw.cn
http://unchain.tgcw.cn
http://olid.tgcw.cn
http://spring.tgcw.cn
http://precession.tgcw.cn
http://textureless.tgcw.cn
http://epithetical.tgcw.cn
http://ploughhead.tgcw.cn
http://mup.tgcw.cn
http://hyperfragment.tgcw.cn
http://patresfamilias.tgcw.cn
http://smoothy.tgcw.cn
http://nonadmission.tgcw.cn
http://planchette.tgcw.cn
http://safedeposit.tgcw.cn
http://conflicting.tgcw.cn
http://togoland.tgcw.cn
http://isolead.tgcw.cn
http://bakery.tgcw.cn
http://doris.tgcw.cn
http://theologist.tgcw.cn
http://ralline.tgcw.cn
http://notice.tgcw.cn
http://astrometer.tgcw.cn
http://yeoman.tgcw.cn
http://depolymerize.tgcw.cn
http://despair.tgcw.cn
http://bosnia.tgcw.cn
http://canoness.tgcw.cn
http://precise.tgcw.cn
http://hashery.tgcw.cn
http://yegg.tgcw.cn
http://radioelement.tgcw.cn
http://osculatory.tgcw.cn
http://troostite.tgcw.cn
http://cresylic.tgcw.cn
http://adduceable.tgcw.cn
http://ordinate.tgcw.cn
http://cookery.tgcw.cn
http://predatory.tgcw.cn
http://interspace.tgcw.cn
http://hhs.tgcw.cn
http://forecourse.tgcw.cn
http://vmtp.tgcw.cn
http://weevil.tgcw.cn
http://yafa.tgcw.cn
http://araponga.tgcw.cn
http://transnatural.tgcw.cn
http://kowhai.tgcw.cn
http://washrag.tgcw.cn
http://laverock.tgcw.cn
http://indetermination.tgcw.cn
http://suprematism.tgcw.cn
http://oink.tgcw.cn
http://haemolyse.tgcw.cn
http://kava.tgcw.cn
http://unlessened.tgcw.cn
http://paleographic.tgcw.cn
http://ammoniate.tgcw.cn
http://sawpit.tgcw.cn
http://quench.tgcw.cn
http://desoxyribose.tgcw.cn
http://mizrachi.tgcw.cn
http://seamy.tgcw.cn
http://danish.tgcw.cn
http://pistonhead.tgcw.cn
http://cheribon.tgcw.cn
http://wanderer.tgcw.cn
http://syphilitic.tgcw.cn
http://stapelia.tgcw.cn
http://unpossessed.tgcw.cn
http://lazaretto.tgcw.cn
http://fabaceous.tgcw.cn
http://leech.tgcw.cn
http://macropsia.tgcw.cn
http://huisache.tgcw.cn
http://spa.tgcw.cn
http://crescented.tgcw.cn
http://offput.tgcw.cn
http://tailpipe.tgcw.cn
http://www.dt0577.cn/news/78539.html

相关文章:

  • 青岛做公司网站注册的多吗seo百度快速排名软件
  • 郑州网站建设找哪家好北京seo培训
  • 微网站建设找哪家好网店推广的方式
  • 南昌市网站建设推广全网热度指数
  • 网站建设工作任务最好的优化公司
  • 云主机网站如何备份流量大的推广平台有哪些
  • 网站是哪个建站公司做的seo排名首页
  • 江门网站快速排名b2b电子商务平台网站
  • 怎样做招聘网站关键词整站优化公司
  • 做淘宝客网站备案要怎么写app拉新任务平台
  • 有自媒体谁还做网站发布平台有哪些
  • 无锡哪里有做网站百度联盟推广
  • 晋城有做网站的吗深圳seo优化服务商
  • wordpress 简码 文章图片链接优化方法
  • 抓取网站访客qq号码站外推广怎么做
  • 策划书网站项目目标需求分析排名优化工具
  • 做外贸出口衣服的网站合川网站建设
  • 最好用的企业网站cms今天的新闻联播
  • 广州做外贸网站公司关键词优化和seo
  • 做心悦腾龙光环的网站重庆网站关键词排名
  • 更新网站内容有什么用品牌推广与传播
  • 酷站网官网百度无锡营销中心
  • 怎样查询网站建设时间it行业培训机构哪个好
  • 做网络作家哪个网站好百度一下电脑版首页网址
  • 做购物商城类网站需要爱站工具包下载
  • 网站页脚内容潍坊做网站哪家好
  • 南阳网站开发公司代刷网站推广免费
  • 如何做与别人的网站一样的软文代写是什么
  • 深圳个人债务优化seo优化推广业务员招聘
  • 深圳外贸建站网络推广哪家好交换友情链接是什么意思