我收到以下错误:
C:\ Area52 \ AndroidProgramming> javac -d。 ex1.java ex1.java:27:错误:
找不到适合println(Object,Object)的方法
System.out.println(players.get(0), batAvg.get(0)); ^ method PrintStream.println(Object) is not applicable (actual and formal argument lists differ in length)
这是我的代码:
package one.exercise;
import java.util.*;
public class ex1
{
public static void main(String[] args)
{
ArrayList players = new ArrayList();
players.add("Joey");
players.add("Thomas");
players.add("Joan");
players.add("Sarah");
players.add("Freddie");
players.add("Aaron");
ArrayList batAvg = new ArrayList();
batAvg.add(.333);
batAvg.add(.221);
batAvg.add(.401);
batAvg.add(.297);
batAvg.add(.116);
batAvg.add(.250);
System.out.println(players.get(0), batAvg.get(0));
System.out.println(players.get(1)); //+ batAvg.get(1));
System.out.println(players.get(2)); //+ batAvg.get(2));
System.out.println(players.get(3)); //+ batAvg.get(3));
System.out.println(players.get(4)); //+ batAvg.get(4));
System.out.println(players.get(5)); //+ batAvg.get(5));
}
}
答案 0 :(得分:4)
System.out.println(players.get(0) + ", " + batAvg.get(0));
更好......
for(int i = 0; i < players.size() && i < batAvg.size(); i++)
System.out.println(players.get(i) + ", " + batAvg.get(i));
如果您可以保证它们的大小始终相同,则可以删除其中一个条件(i < players.size()
或i < batAvg.size()
)。
答案 1 :(得分:0)
您有两种选择:
答案 2 :(得分:0)
问题在于您尝试在PrintStream上使用println方法,该方法只接受一个参数。
请参阅javadoc。
不是将你想要的两个字符串作为不同的参数,而是将它们连接在一起,如前面的答案中所示,以获得一个参数并满足println的要求。