Reputation: 31
public static String[][] possibleOutcomes(Scanner fileScan,int weaponNumber)
{
int numberOfOutcomes = (int)Math.pow(weaponNumber,2);
String[][] outcomes = new String[numberOfOutcomes][numberOfOutcomes];
String line = fileScan.nextLine();
Scanner lineScan = new Scanner(line);
fileScan.nextLine();
fileScan.nextLine();
while (fileScan.hasNextLine())
{
String userWeapon = lineScan.next();
String computerWeapon = lineScan.next();
String possibleTie = lineScan.next();
if (possibleTie.equals("ties"))
outcomes[userWeapon][computerWeapon] = possibleTie;
else
outcomes[userWeapon][computerWeapon] = lineScan.next();
}
return outcomes;
}
Error Message: I think its saying that my inputs are ints even though they are set as String. What should I do?
RPSL.java:57: error: incompatible types: String cannot be converted to int outcomes[userWeapon][computerWeapon] = possibleTie;
RPSL.java:57: error: incompatible types: String cannot be converted to int
outcomes[userWeapon][computerWeapon] = possibleTie;
Upvotes: 0
Views: 44
Reputation: 603
You declare userWeapon
and computerWeapon
as Strings, which you can't access an array with. Read an integer from the scanner instead (see Scanner#nextInt
).
int userWeapon = lineScan.nextInt();
int computerWeapon = lineScan.nextInt();
String possibleTie = lineScan.next();
if (possibleTie.equals("ties"))
outcomes[userWeapon][computerWeapon] = possibleTie;
else
outcomes[userWeapon][computerWeapon] = lineScan.next();
Upvotes: 1