1. 就是红色圈出来这部分就是运行时的效果,应该怎么实现呢,想了for循环 for (int i = 0; i <carnum1 ; i++) {
Scanner input=new Scanner(System.in);
String temp =input.nextLine();
String a[]=temp.split(" ");
int num1=Integer.parseInt(a[0]);
int num2=Integer.parseInt(a[1]);
switch (num1){
case 1: System.out.println("奥迪");break;
case 2: System.out.println("马自达");break;
case 3: System.out.println("皮卡雪");break;
case 4: System.out.println("金龙");break;
case 5: System.out.println("松花江");break;
case 6: System.out.println("依维柯");break;}
但是输出以一次一次输出的,
java 在for循环中使用scanner然后,输入三组数据,然后判断
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- Gosse0405 2020-03-11 23:20关注
/** * 作者:WGS * 微信:w1150111308 * Q Q:1150111308 * 邮箱:gosse0405@163.com */ public class Answer { static Scanner sc = new Scanner(System.in); static String[] cars = {"", "奥迪A4", "马自达6", "皮卡雪6", "金龙", "松花江", "依维柯"}; static int[] prices = {0, 500, 400, 450, 800, 400, 1000}; static int[] persons = {0, 4, 4, 4, 20, 0, 0}; static int[] tons = {0, 0, 0, 2, 0, 4, 20}; public static void main(String[] args) { System.out.println("欢迎使用租车系统"); // 输入的数字 int whether = inputNum("您是否要租车:1是,0否"); switch (whether) { case 1: // 租车系统内容 content(); // 输入租车数量 int num = 0; while (true) { num = inputNum("请输入要租车的数量:"); if (num > 0 && num < cars.length) { break; } else { System.out.println("您输入的内容不在系统范围,请重新输入!"); } } // 执行租车流程和账单结算 total(inputGroupStr("请输入您要租车的序号和天数:", num)); break; case 0: System.out.println("欢迎您下次使用本系统!"); break; default: System.out.println("输入错误的数字"); } } /** * 租车主体内容 */ public static void content() { System.out.println("您可租车的类型及其节目表如下:"); for (int i = 1; i < cars.length; i++) { System.out.println( "序号-" + i + "\t" + "汽车名称:" + cars[i] + "\t" + "租金:" + prices[i] + "/天 \t" + "容量:" + (persons[i] != 0 ? ("最多载人" + persons[i] + "人") : "") + (persons[i] != 0 && tons[i] != 0 ? "," : "") + (tons[i] != 0 ? ("最多载货" + tons[i] + "吨") : "") ); } System.out.println(); } /** * 账单计算 */ public static void total(int[][] orderDays) { System.out.println("您的账单如下:"); int total = 0; for (int i = 0; i < orderDays.length; i++) { int order = orderDays[i][0]; int days = orderDays[i][0]; total += prices[order] * days; System.out.println(cars[order] + " \t" + days + "天"); } System.out.println("总价格:" + total); } /** * 输入单个数字内容 * @return */ public static int inputNum(String info) { System.out.println(info); String s = sc.nextLine(); int num = -1; try { num = Integer.parseInt(s); } catch (NumberFormatException e) { return num; } return num; } /** * 输入三组数字内容 * @return */ public static int[][] inputGroupStr(String infoGroup, int num) { int[][] nums = new int[num][2]; System.out.println(infoGroup); for (int i = 0; i< num; i++) { while (true) { try { String[] s = sc.nextLine().split(" "); int order = Integer.parseInt(s[0]); int days = Integer.parseInt(s[1]); if (order >= cars.length || order <= 0 || days >= cars.length && days <= 0) { System.out.println("您输入的内容不在系统范围,请重新输入!"); } else { nums[i][0] = order; nums[i][1] = days; break; } } catch (Exception e) { System.out.println("您输入的内容不规范,请重新输入!"); System.out.println("【示例】:2 3"); } } } return nums; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥100 有人会搭建GPT-J-6B框架吗?有偿
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名