黑马程序员---------java判断循环语句
2015-05-15 16:39
330 查看
------- <a href="http://www.itheima.com" target="blank">android培训</a>、<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------
判断语句
1、IF
public class TestAge{
public static void main(String args[]){
TestAge t = new TestAge();
t.age(75);
}
public void age(int age){
if (age< 0) {
System.out.println("不可能!");
} else if (age>250) {
System.out.println("是个妖怪!");
} else {
System.out.println("此人芳龄 " + age +
" 马马乎乎啦!");
}
}
}
2、SWITCH
public class Test{
public static void main(String args[]){
int i = 1;
switch (i) {
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
//break;
default:
System.out.println("default");
break;
}
}
}
循环语句
1、循环语句分类
for 循环
while 循环
do/while 循环
2、for 循环
public class ForLoop {
public static void main(String args[]){
int result = 0;
for(int i=1; i<=100; i++) {
result += i;
}
System.out.println("result=" + result);
}
}
3、while 循环
public class WhileLoop {
public static void main(String args[]){
int result = 0;
int i=1;
while(i<=100) {
result += i;
i++;
}
System.out.println("result=" + result);
}
}
4、do/while 循环
public class WhileLoop {
public static void main(String args[]){
int result = 0, i=1;
do{
result += i;
i++;
}while(i<=100);
System.out.println("result=" + result);
}
}
break and continue 语句
1、break只能用于switch语句和循环语句中。
continue 只能用于循环语句中。
2、Break示例
public class TestBreak{
public static void main(String args[]){
for(int i = 0; i<10; i++){
if(i==3)
break;
System.out.println(" i =" + i);
}
System.out.println("Game Over!");
}
}
3、Continue示例
public class ContinueTest {
public static void main(String args[]){
for (int i = 0; i < 100; i++) {
if (i%10==0)
continue;
System.out.println(i);
}
}
}
判断语句
1、IF
public class TestAge{
public static void main(String args[]){
TestAge t = new TestAge();
t.age(75);
}
public void age(int age){
if (age< 0) {
System.out.println("不可能!");
} else if (age>250) {
System.out.println("是个妖怪!");
} else {
System.out.println("此人芳龄 " + age +
" 马马乎乎啦!");
}
}
}
2、SWITCH
public class Test{
public static void main(String args[]){
int i = 1;
switch (i) {
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
//break;
default:
System.out.println("default");
break;
}
}
}
循环语句
1、循环语句分类
for 循环
while 循环
do/while 循环
2、for 循环
public class ForLoop {
public static void main(String args[]){
int result = 0;
for(int i=1; i<=100; i++) {
result += i;
}
System.out.println("result=" + result);
}
}
3、while 循环
public class WhileLoop {
public static void main(String args[]){
int result = 0;
int i=1;
while(i<=100) {
result += i;
i++;
}
System.out.println("result=" + result);
}
}
4、do/while 循环
public class WhileLoop {
public static void main(String args[]){
int result = 0, i=1;
do{
result += i;
i++;
}while(i<=100);
System.out.println("result=" + result);
}
}
break and continue 语句
1、break只能用于switch语句和循环语句中。
continue 只能用于循环语句中。
2、Break示例
public class TestBreak{
public static void main(String args[]){
for(int i = 0; i<10; i++){
if(i==3)
break;
System.out.println(" i =" + i);
}
System.out.println("Game Over!");
}
}
3、Continue示例
public class ContinueTest {
public static void main(String args[]){
for (int i = 0; i < 100; i++) {
if (i%10==0)
continue;
System.out.println(i);
}
}
}
相关文章推荐
- 黑马程序员_java判断与循环语句
- 黑马程序员_java逻辑循环语句(判断,循环)
- 黑马程序员-判断语句与循环语句
- 黑马程序员_JAVA中的判断结构、选择结构和循环结构
- 黑马程序员:JAVA判断语句、选择语句、循环语句介绍
- 黑马程序员——高新技术---Java基础语法-循环结构和跳转语句
- java、判断语句及循环语句
- Java基础(三) Java变量、操作符及判断和循环语句之(二)
- 黑马程序员_JAVA笔记03——循环语句与函数
- java判断与循环语句
- 黑马程序员___Java中的循环语句
- java判断与循环语句
- 黑马程序员-java学习笔记-循环语句
- 黑马程序员_判断语句与循环语句
- java入门基础知识:运算符和循环语句,判断语句的区别
- java判断与循环语句
- 从”JAVA“而终 8:java循环判断语句讲解
- 黑马程序员_java基础学习笔记02_选择结构和循环语句语句
- java基础——判断与循环控制语句
- Java判断与循环语句