流程控制基础

---------分支循环流程控制---------

/*int a = 10;
if(a == 20){

}else if(){

}else if(){

}else{

}*/

//一般情况下,比较定值,使用switch,表达式的值最好是int以下类型的变量
//最好表达式不要用String类型
/*switch(表达式){
case 值:
//代码1
//break; 如果没有break,代码1执行完成会后会继续穿透执行下面代码2中的内容
case 值:
//代码2
break;
default:
break;
}*/

/*int a = 10;
switch(a){
case 10:
System.out.println("哈哈");
case 20:
System.out.println("嘻嘻");
case 30:
System.out.println("嘿嘿");
break;
case 40:
System.out.println("呵呵");
}*/


/*---------循环---------
循环初始值
循环首先要注意的问题
1.循环的基本语法
2.给循环初始值,给判断,给循环自增变量
都是为了额控制循环次数*/


/*int a =10;
while(a < 20){
//循环体
a++;
}*/

//下面这里的变量a就是来控制循环次数的
/*int a = 1;
while(a <= 5){
System.out.println("哈哈哈哈");
a++;
}*/

//下面这里的a,不但是控制循环次数,还能做到和sum进行计算
/*int a = 1;
int sum = 0;
while(a <= 5){
sum += a;
a++;
}*/

/*int a = 1;
int sum = 0;
do{
sum += a;
a ++;
}while(a < 0);*/


//下面的情况使用do...while比较方便
/*String choice = "n";
do{
System.out.println("欢迎使用XXX系统");
System.out.println("1.XXXX");
System.out.println("2.XXX");
System.out.println("请选择(1-2)");
int n = input.nextInt();
//....

System.out.println("你要继续吗?");
choice = input.next();
}while(choice.equals("y"));*/


/*for
for(int i=0; i<5; i++){
System.out.println(i);
}*/

//在某个范围之内重复的执行某个代码,其实基础的循环变种无非就是下面几个
//筛选 求和 计数

//求成绩,统计人数
/*int sum = 0;
int count = 0;
for(int i=1; i<=5; i++){
int score = input.nextInt();
sum += score;
if(score >= 60){
count ++;
}
}*/

/*int a = 34536;
System.out.println(a % 10);
System.out.println(a / 10 % 10);
System.out.println(a / 100 % 10);
System.out.println(a / 1000 % 10);
System.out.println(a / 10000 % 10);
System.out.println(a / 100000 % 10);

while(a != 0){
int temp = a % 10;
System.out.print(temp);
a = a / 10;
}*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值