java system.in 数字,请教一个简单的java程序,差一步就完成了,就是在程序前面加一个数字代表接下来要测试几组数据.importjava.util.Scanner;publicclass...

请教一个简单的java程序,差一步就完成了,就是在程序前面加一个数字代表接下来要测试几组数据.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner cin = new Scanner(System.in);

int[] t1 = { 123,456,789,336,775,566 };

int[] t2 = { 456,789,888,558,666,221 };

int[] t3 = { 9000,5000,6000,10000,12000,7000 };

System.out.print("");

while (cin.hasNext()){

String str = cin.nextLine();

String[] substr = str.split(" ");

int a1 = Integer.parseInt(substr[0]);

int b = Integer.parseInt(substr[1]);

if (t1[0] == a1 && t2[0] == b)

System.out.println(t3[0]);

else if (t1[1] == a1 && t2[1] == b)

System.out.println(t3[1]);

else if (t1[2] == a1 && t2[2] == b)

System.out.println(t3[2]);

else if (t1[3] == a1 && t2[3] == b)

System.out.println(t3[3]);

else if (t1[4] == a1 && t2[4] == b)

System.out.println(t3[4]);

else if (t1[5] == a1 && t2[5] == b)

System.out.println(t3[5]);

else

System.out.println("error");

}

}

}

照这样,例如输入:

123 123

456 789

789 789

结果是:

error

5000

error

但是期望的输入方式是:

3

123 123

456 789

789 789

此时3就代表输入了3组数据,输出内容不变.关键是这个代表输入了几组数据的整数应该如何加?我尝试用nextInt失败了,提示在Integer.parseInt附近出错.

作业帮用户2016-11-29举报

6c0a0adef10d1043fa4f41a7897345ed.png

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值