【发布时间】:2021-06-16 09:55:49
【问题描述】:
您好,我正在尝试重新创建足球锦标赛,并且能够使用地图创建组,但现在想将积分添加到每个国家/地区。有人有什么好主意吗?请看看我已经做了什么。
import java.util.*;
class EuroGroupStages {
public static void main(String args[]) {
Map<String, Set<String>> groupA;
//public EuroGroupStages()
// {
groupA = new TreeMap<>();
// }
//public void addCountries(String aGroup)
// {
Scanner keyboard = new Scanner(System.in);
String aCountry, aGroup;
char anAnswer;
boolean flag = true;
while(flag)
{
Set<String> country = new HashSet<>();
System.out.print("Please enter the group name (A-D):");
aGroup = keyboard.next();
for(int i = 1; i < 5; i++)
{
System.out.print("Please enter a country");
aCountry = keyboard.next();
country.add(aCountry);
}
System.out.print("Do you want to continue? Y/N");
anAnswer = keyboard.findWithinHorizon(".", 0).charAt(0);
if(anAnswer == 'N' || anAnswer == 'n')
{
flag = false;
}
groupA.put(aGroup, country);
}
System.out.println(groupA);
keyboard.close();
// }
}
}
【问题讨论】:
标签: java class methods collections maps