标签:
一:数据类型
基本类型,字符串类型和null类型可指定直接量
二:条件语句
if
if-else
switch
没有匹配项,逐条执行
package one; public class switchs1 { public static void main(String[] args) { int x= 0; switch(x){ default: System.out.println("default"); case 1: System.out.println(1); case 2: System.out.println(2); } } }
从匹配项开始执行
package one; public class switchs2 { public static void main(String[] args) { int x= 0; switch(x){ default: System.out.println("default"); case 0: System.out.println(0); case 1: System.out.println(1); case 2: System.out.println(2); } } }
package one; public class switchs2 { public static void main(String[] args) { int x= 0; switch(x){ case 0: System.out.println(0); case 1: System.out.println(1); case 2: System.out.println(2); default: System.out.println("default"); } } }
三:循环语句
for
while
do-while
package one; public class Xunhuan { public static void main(String[] args) { for(int a = 0; a < 10; a++){ System.out.print(a); } System.out.println(); int x = 0; while(x < 20){ System.out.print(x); x++; } System.out.println(); int y = 0; do{ System.out.print(y); y++; }while(y < 10); } }
四:跳转语句
break(跳出整个循环)
continue(进入下一次循环)
package one; public class tiaozhuan { public static void main(String[] args) { for(int a = 0; a < 10; a++){ System.out.print(a); if(a % 2 == 0){ continue; } System.out.println("$"); } } }
标签:
原文地址:http://www.cnblogs.com/kmust-hechi/p/5888446.html