import java.util.Scanner; public class fangfa { public static void main(String[]args){ //定义每个人的快捷拨号键 int father=1; int mather = 2; int gandfather = 3; int gandmather =4; 用while 循环以便拨号错误后 重新拨号 while (true){ System.out.println("你要打给谁"); Scanner sc =new Scanner(System.in); int bohao=sc.nextInt(); //用if 判断号码对应的人 if (bohao==1){ System.out.println("正在拨通爸爸的号码"); break; }if (bohao==2){ System.out.println("拨通妈妈的号码"); break; }if (bohao==3){ System.out.println("拨通爷爷的号码"); break; }if (bohao==4){ System.out.println("拨通奶奶的号码"); break; }else{ System.out.println("你输入的号码有误"); } } System.out.println("正在呼叫"); } }
Java while 循环 拨号
最新推荐文章于 2024-02-29 20:14:57 发布