switch(A),括号中A的取值只能是整型或者可以转换为整型的数值类型,比如byte.short.int.char.string(jdk1.7后加入)还有枚举:需要强调的是:long是不能用在switch上的. case(B),括号中的B只能是常量,也就是不能是普通的变量,只能是常量整数值或者string值,或者是static final 定义的变量.才可以放进去.且case里面的数字 一定要和switch中的A类型相同.也就说明,case里面不是整数常量就是字符串常量.没有其他的常量可以存在…
/* switch(表达式或变量){ case value1:{ 语句体1; break; } case value2:{ 语句体2; break; } ... default:{ 语句体n+1; break; } } */ public class SwitchDemo{ public static void main(String[] args){ int i = 1; long lon = 10L; byte b = 10; short s = 10; String str = "abc&…
一.if条件语句 示例: import java.util.Scanner; public class Test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请输入学生的成绩:"); int num = in.nextInt(); ){ System.out.println("满分!"); } &&…
Java 分支结构 - if...else/switch 顺序结构只能顺序执行,不能进行判断和选择,因此需要分支结构. Java 有两种分支结构: if 语句 switch 语句 if 语句 一个 if 语句包含一个布尔表达式和一条或多条语句. 语法 if 语句的用语法如下: if(布尔表达式) { //如果布尔表达式为true将执行的语句 } 如果布尔表达式的值为 true,则执行 if 语句中的代码块,否则执行 if 语句块后面的代码. Test.java 文件代码: public clas…
public class Test{ public static void main(String args[]){ int x = 10; if(x<20){ System.out .println("这就是if语句"); } }} 这是 if 语句 public class Test{ public static void main(String args[]){ int x=30; if(x<10){ System.out.println("这是if语句&q…
switch ,方便的条件分支语句 package main import "fmt" import "time" func main() { 一个基本的 switch. i := 2 fmt.Print("write ", i, " as ") switch i { case 1: fmt.Println("one") case 2: fmt.Println("two") case 3…
分支结构与数组 什么是分支结构? 分支结构是用户或者程序可以选择下一步执行哪个语句 分支结构有哪些? If If Else If Else If Switch 在初学者的学习过程中第一种和第二种比较普遍 数组是什么? 数组是内存中一串连续的空间 跟变量比较像 怎么样创建数组? 数组类型 数组名[数组容量] = {数组定义的内容};…
[java基础]分支结构2 switch case /** 文件路径:G:\JavaByHands\if-else\ 文件名称:switchcase.java 编写时间:2016/6/6 作 者:郑晨辉 编写说明:switch case代码示例 */ public class switchcase { public static void main(String[] args){ int a = 4; switch(a){ case(1): System.out.println("输出的是1&q…