java循环和switch混合简单应用
来源:互联网 发布:c语言排队系统 编辑:程序博客网 时间:2024/06/08 09:50
import java.io.IOException;import java.util.Scanner;public class Lianxi1 {public static void main(String[] args) throws IOException {// TODO Auto-generated method stubScanner in = new Scanner(System.in);System.out.println("购物结算\n" + "*************************************\n" + "请选择购买商品的编号:\n"+ "1.T恤\t2.网球鞋\t3.网球拍\n" + "*************************************\n" + "请输入商品编号:");int bian;bian = in.nextInt();// 此处也可以用字符串定义,String a,//判断字符串相等的时候,用a.equals("y"),返回的是布尔类型的值。char a = 0;while (true) {switch (bian) {case 1:System.out.println("T恤\t¥245\n");break;case 2:System.out.println("网球鞋\t¥570\n");break;case 3:System.out.println("网球拍\t¥870\n");break;}System.out.println("是否继续(y/n):");a = (char) System.in.read();if (a == 'y') {System.out.println("请输入商品编号(1,2,3):");bian = in.nextInt();}if (a == 'n') {System.out.println("结束!");break;} }}}
import java.util.Scanner;public class Ch03 {public static void main(String[] args) {// TODO Auto-generated method stub//提示信息System.out.println("**************************");System.out.println("请选择购买的商品编号");System.out.println("1.T恤\t2.网球鞋\t3.网球拍");System.out.println("****************");Scanner sc=new Scanner(System.in);String str=null;//循环do{//输入编号System.out.print("请输入商品编号");//得到编号int num=sc.nextInt();//根据编号得到价格//根据编号显示价格switch (num) {case 1:System.out.println("T恤\t\t200");break;case 2:System.out.println("网球鞋\t\t570");break;case 3:System.out.println("网球拍\t\t300");break;default:System.out.println("输入编号有误");break;}//得到是否继续System.out.print("是否继续(y/n)");str=sc.next();} while(str.equals("y"));//根据输入信息确定是否继续System.out.println("谢谢使用");}}
阅读全文
0 0
- java循环和switch混合简单应用
- switch的简单应用
- C#实现简单switch循环
- java Enum在switch case 中的简单应用
- java switch 多循环篇
- C++ for和switch循环
- java菜鸟的回炉之旅之九---switch语句和while循环、do while循环
- while循环下switch.....case的应用
- 选择和循环混合程序设计
- JAVA、VC++和MATLAB的混合编程应用
- java switch语句应用举例
- RE:JAVA学习-循环应用和数组
- if和switch的应用
- switch循环
- switch循环
- JAVA---关于分支结构switch和循环结构for语句的特例
- C# switch 语句的简单应用
- while循环下switch.....case的应用2
- Material design的学习笔记
- library not loaded 错误
- intent传递数据太大,报TransactionTooLargeException异常
- 在CentOS7中设置Tomcat开机自启动
- 关于unity3d for ARkit(一)
- java循环和switch混合简单应用
- 来听听资深设计师的想法(上)
- 关于C++的struct
- 机试题详解
- 3.Windows核心编程-线程及线程调度
- MySQL热备手顺
- 静态顺序表的实现
- kafka集群搭建
- HDU 6035 Colorful Tree (树形DP,dfs)