第四章总结

1.

public class Sizongjie {

public static void main(String[] args) {

// TODO Auto-generated method stub

int phonenumber=123456789;//创建变量,保存电话号码

if(phonenumber!=84972266) {//如果此号码不是8497226

System.out.println("对不起,您拨打的号码不存在!");//提示号码不存在

}

}

}

2.

public class Yongc {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("欢迎光临,请问有多少人用餐?");

int count =9;

System.out.println("回答:"+count+"人");

if(count<=4) {

System.out.println("客人请到大厅4人桌用餐");

}else if(count>4&count<=8) {

System.out.println("客人请到大厅8人桌用餐");

}else if(count>8&count<=16) {

System.out.print("客人请到楼上包厢用餐");

}else {

System.out.println("抱歉,我们店暂时没有这么大的包厢");

}

}

}

3.

import java.util.Scanner;

public class Chenji {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc =new Scanner(System.in);//创建扫描器,接收控制台输入内容

System.out.println("请输入成绩");//输出字符串

int grade =sc.nextInt();//获取控制台输入的数字

switch(grade) {//使用 switch 判断数字

case 10://如果等于 10,则继续执行下一行代码

case 9:

System.out.println("成绩为优");

break;//结束判断

case 8:

System.out.println("成绩为良");

break;

case 7:

case 6:

System.out.println("成绩为中");

break;

case 5:

case 4:

case 3:

case 2:

case 1:

case 0:

System.out.println("成绩为差");

break;

default://如果不符合以上任何一个结果

System.out.println("成绩无效");//输出成绩无效

}

sc.close();//关闭扫描器

}

}

循环语句

while循环

do while循环

for循环

while 嵌套 do while

do while 嵌套while

public class Uvvv {

public static void main(String[] args) {

// TODO Auto-generated method stub

for (int i = 1; i < 20; i++){

if (i % 2 == 0) { //如果i是偶数

System.out.println(i); //输出i的值

break; //结束循环

}

}

System.out.println("---end---"); //结束时输出一行文字

}

}

public class Aaa {

public static void main(String[] args) {

// TODO Auto-generated method stub

for (int i = 1; i <= 20; i++){

if (i % 2 == 0){ //如果i是偶数

continue; //跳到下一循环

}

System.out.println(i); //输出i的值

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值