switch分支与if分支用法事例

在这里插入图片描述

//switch分支用法
/*public class Zuoye5{
public static void main(String[] args){
System.out.println(“欢迎来到自动拨号系统”);
int num =(int)(Math.random()8);
switch (num){
case 1:;
System.out.println(“拨打爸爸的号”+num);break
case 2 :;
System.out.println(“拨打妈妈的号”+num);break
case 3:;
System.out.println(“拨打爷爷的号”+num);break
case 4:;
System.out.println(“拨打奶奶的号”+num);break
default:System.out.println(“对不起,没有该号码”);
}
}
}
/

//if分支用法

import java.util.Scanner;
public class Zuoye5{
public static void main(String[] args){
System.out.println(“欢迎来到自动拨号系统”);
System.out.println(“请输入快捷数字”);
Scanner sc =new Scanner(System.in);
int num=sc.nextInt();
if(num==1){
System.out.println(“爸爸的电话”);

	}else if(num==2){
		System.out.println("妈妈的电话");
	}else if(num==3){
		System.out.println("爷爷的电话");
	}else if(num==4){
		System.out.println("奶奶的电话");
	}
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值