package dxc2013_6_23.test;
//读入一支球队的名字,输出该球队夺冠的年份列表。例如,读入“巴西”,应当输出1958 1962 1970 1994 2002读入“荷兰”,应当输出没有获得过世界杯
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;public class Test8 { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该年没有举办世界杯,则输出:没有举办世界杯。
// WorldCup wp=new WorldCup();
Map<Integer,WorldCup> map=new HashMap<Integer, WorldCup>();
map.put(1930, new WorldCup(1,"乌拉圭"));
map.put(1934, new WorldCup(2,"意大利"));
map.put(1938, new WorldCup(3,"意大利"));
map.put(1950, new WorldCup(4,"乌拉圭"));
map.put(1954, new WorldCup(5,"德国"));
map.put(1958, new WorldCup(6,"巴西"));
map.put(1962, new WorldCup(7,"巴西"));
map.put(1966, new WorldCup(8,"英格兰"));
map.put(1970, new WorldCup(9,"巴西"));
map.put(1974, new WorldCup(10,"德国"));
map.put(1978, new WorldCup(11,"阿根廷"));
map.put(1982, new WorldCup(12,"意大利"));
map.put(1986, new WorldCup(13,"阿根廷"));
map.put(1990, new WorldCup(14,"德国"));
map.put(1994, new WorldCup(15,"巴西"));
map.put(1998, new WorldCup(16,"法国"));
map.put(2002, new WorldCup(17,"巴西"));
map.put(2006, new WorldCup(18,"意大利"));
System.out.println("请输入一个国家");
Scanner inpot=new Scanner(System.in);
String country=inpot.next();
Collection coll=map.values();
Iterator<?> it=coll.iterator();
while(it.hasNext()){
Object key=it.next();
if(map.get(key).equals(country)){
System.out.println(key);
}
}
}
}//定义一个世界杯类
class WorldCup{
private int ss ;//年
private String country;//国家
public WorldCup(String country) {
this.country = country;
}
public WorldCup(int period, String country) {
this.ss = ss;
this.country = country;
} public int getYrear() {
return ss;
} public void setYrear(int yrear) {
this.ss = yrear;
} public String getCountry() {
return country;
} public void setCountry(String country) {
this.country = country;
} @Override
public String toString() {
return country;
}
}
解决方案 »
- JTree折叠和展开时用+和-号显示
- 散分了!想交几个熟悉JAVA/swing的GUI设计的朋友?
- 我调用它的时候传进的参数类型是不定的,我怎么做才能把传经去的类型转化为原来的类型呢?
- 请问一个关于流式套接字的问题?
- 送分问题
- 如何不要让TextField中的内容不被覆盖
- JAVA 在SWING 中显示网页上验证码图片的代码,谢谢
- 关于JBuilder8 运行单个文件
- 那里有Java可视化开发环境可下载,同时带有文档说明更好,谢谢
- 请问谁对用blowfish来做JAVA的加密解密比较熟悉,请帮忙写个文本的加密解密类,(我这有一个但是写得不很成熟不能解密)
- Java UDP端口独占问题
- java udp通信求助
2: 哪一行出现异常, 这是可以知道的;
3: 找到哪个是null, 然后出来(可以debug跟踪);