java多组数据 java可不可以连续输入多组两个数当输入0 0时结束然后输出之前输入的多组两个数的和例如:输入:12 13 10 20 0 0输出:25 30 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是一个输入流,Scanner scan = Scanner(System.in);自己在API中查一下Scanner怎么用,就ok了。 Scanner scan = Scanner(System.in);我会用!我要的是连续输入,当输入0 0 时结束然后一起输出结果 import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Map.Entry;import java.util.Scanner;import java.util.Set;public class ScannerDemo { public static void main(String[] args) { Map<Integer,Integer> li=new HashMap<Integer,Integer>(); Scanner read=new Scanner(System.in); boolean flag=true; while(flag) { int a=read.nextInt(); int b=read.nextInt(); if(a!=0&&b!=0) li.put(a, b); else flag=false; } Set<Map.Entry<Integer,Integer>> keySet2=li.entrySet(); Iterator<Map.Entry<Integer,Integer>> it=keySet2.iterator(); while(it.hasNext()) { Map.Entry<Integer,Integer> relation=it.next(); Integer k=relation.getKey(); Integer v=relation.getValue(); System.out.println(k+v); } }} 将大长度的byte[]数组按照数组中值为指定的两个数值分割为集合 如何截取String中指定字符后的字符串 谁能说的让我非常清楚i++ 和++i 的区别。 字符串问题 请问如何为JMenu添加组合快捷键? 刚开始看Java基础,请大家帮忙 请问SWING的UI类如何使用,最好有例子。 50分 问一个比较难的GUI的问题 请问如何通过 jdbc api 设置 access DB 中的 连接帐号 密码 ? 我有一到难题请帮帮小妹。 关于反射的一个小问题,不知道错误在哪。 又是HELLO WORLD 大家帮我看看
Scanner scan = Scanner(System.in);
自己在API中查一下Scanner怎么用,就ok了。
我会用!我要的是连续输入,当输入0 0 时结束然后一起输出结果
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;public class ScannerDemo {
public static void main(String[] args) {
Map<Integer,Integer> li=new HashMap<Integer,Integer>();
Scanner read=new Scanner(System.in);
boolean flag=true;
while(flag)
{
int a=read.nextInt();
int b=read.nextInt();
if(a!=0&&b!=0)
li.put(a, b);
else
flag=false;
}
Set<Map.Entry<Integer,Integer>> keySet2=li.entrySet();
Iterator<Map.Entry<Integer,Integer>> it=keySet2.iterator();
while(it.hasNext())
{
Map.Entry<Integer,Integer> relation=it.next();
Integer k=relation.getKey();
Integer v=relation.getValue();
System.out.println(k+v);
} }}