这是我的完整代码。我的挑战是在最后 3 行!我无法将参数 (int r) 发送给 findColor(int r)。非常感谢任何帮助。谢谢
import java.util.*;
public class NewClass {
private HashMap <Character,HashSet> colorMap ;
public NewClass() {
colorMap = new HashMap<Character, HashSet>();
}
public void addColor(){
HashSet a1 = new HashSet();
a1.add("Yellow");
a1.add("Blue");
a1.add("Pink");
colorMap.put('X', a1);
HashSet a2 = new HashSet();
a2.add("White");
a2.add("Brown");
a2.add("Blue");
a2.add("Black");
colorMap.put('W', a2);
}
public Set<String> findColor(int r)
{
Set<String> colors = new HashSet<String>();
{
for(Character m : colorMap.keySet())
if(r < colorMap.size())
{
Set<String> zone = colorMap.get(m);
System.out.println("Zone " + zone + " has more than " + r + " colors");
}
}
return colors;
}
public static void main(String [] args){
Set<String> colors;
NewClass a = new NewClass();
Scanner input = new Scanner(System.in);
System.out.print("Enter a numbers \n");
int r = input.nextInt();
colors = findColor(r);
a.findColor(r);
}
}
非常感谢任何帮助。谢谢!