一、顺序结构
顺序结构是Java的基本结构,除非特别指明,否则就按照顺序一句一句执行
顺序结构是最简单的算法结构

它是任何一个算法都离不开的一种基本结构
例:
public class ShunXuDemo { public static void main(String[] args) { System.out.println("hello 1"); System.out.println("hello 2"); System.out.println("hello 3"); System.out.println("hello 4"); System.out.println("hello 5"); }}运行结果
二、选择结构
1. if单选择结构
2.if双选择结构
3.if多选择结构
4.嵌套的if结构
5.switch多选择结构
1. if 单选择结构

语法
if(布尔表达式){ //如果布尔表达式为ture将执行的语句}例:输入一串字符判断是否等于hello,是则输出hello,不是则输出End
public class ifDemo01 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入内容:"); String str = scanner.nextLine(); //equals:判断字符串是否相等 if (str.equals("hello")){ System.out.println(str); } System.out.println("End"); scanner.close(); }}运行结果
2. if 双选择结构

语法
if(布尔表达式){ //如果布尔表达式为ture将执行的语句}else{ //如果布尔表达式为false将执行的语句 }例:输入分数大于等于60分输出及格,否则输出不及格
public class IfDemo02 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入成绩:"); double score = scanner.nextDouble(); if (score >= 60){ System.out.println("及格"); } else{ System.out.println("不及格"); } scanner.close(); }}运行结果

3. if 多选择结构

语法
if(布尔表达式1){ //如果布尔表达式1为ture将执行的语句}else if(布尔表达式2){ //如果布尔表达式2为ture将执行的语句}else if(布尔表达式3){ //如果布尔表达式3为ture将执行的语句}else{ //如果以上布尔表达式都不为ture将执行的语句}例:
public class IfDemo03 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入成绩:"); double score = scanner.nextDouble(); if (score == 100){ System.out.println("满分"); } else if ( score < 100 && score >= 90) { System.out.println("A级"); } else if ( score < 90 && score >= 80){ System.out.println("B级"); } else if ( score < 80 && score >= 70){ System.out.println("C级"); } else if ( score < 70 && score >= 60){ System.out.println("D级"); } else if (score < 60){ System.out.println("不及格"); } else{ System.out.println("输入错误!"); } }}运行结果
注:
- if 语句最多只有一个 else
- if 语句可以有若干个 else if 语句
- 所有的else if 语句都在 else 语句之前,else 语句在所有的 else if 语句之后
- 一旦有一个 else if 语句为 ture ,其他的 else if 以及 else 语句都将跳过执行
4. if 的嵌套结构
语法
if(布尔表达式1){ //如果布尔表达式1为ture将执行的语句 if(布尔表达式2){ //如果布尔表达式2为ture将执行的语句 }}5.switch多选择结构
- switch case 语句判断一个变量与一系列值中某个值是否相等,每一个值称为一个分支
- switch 语句中的变......
原文转载:http://www.shaoqun.com/a/885615.html
跨境电商:https://www.ikjzd.com/
retriever:https://www.ikjzd.com/w/773
3suisses:https://www.ikjzd.com/w/412
立刻网:https://www.ikjzd.com/w/2323
一、顺序结构顺序结构是Java的基本结构,除非特别指明,否则就按照顺序一句一句执行顺序结构是最简单的算法结构它是任何一个算法都离不开的一种基本结构例:publicclassShunXuDemo{publicstaticvoidmain(String[]args){System.out.println("hello1");System.out.println("hell
深圳罗湖火车站附近酒店有哪些?:http://www.30bags.com/a/397765.html
深圳罗湖火车站有到珠海香洲的车吗?最晚一班是几点?:http://www.30bags.com/a/397089.html
深圳罗湖口岸到香港海洋公园怎么走?:http://www.30bags.com/a/404138.html
深圳罗湖口岸的通关时间是什么时候?:http://www.30bags.com/a/396737.html
男人经常㖭我的下面 亲爱的你那里的水好甜啊:http://lady.shaoqun.com/a/247977.html
口述实录:我和父亲那难以启齿的秘密:http://lady.shaoqun.com/a/71480.html
好紧好大快点舒服使劲小说 他两个朋友做了我一晚:http://lady.shaoqun.com/a/247535.html
男人爱㖭女人下边 被㖭下面是什么感觉:http://lady.shaoqun.com/m/a/247485.html
男人想得到中年女人,钱不重要,重要的是做好三件事,迟早会得到:http://lady.shaoqun.com/a/424242.html
爱与性|男女双方都需要理解的7种"爱"。保持新鲜。看看吧!:http://lady.shaoqun.com/a/424243.html
多久做爱一次最好?:http://lady.shaoqun.com/a/424244.html
如果你想"泡"一个40岁左右的女人,钱不重要。你应该经常说这些话:http://lady.shaoqun.com/a/424245.html
没有评论:
发表评论