0
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;

1
  • String userWeapon = lineScan.next(); arrays are not accessible by String. Do you need to convert to a int ? Commented Dec 19, 2019 at 2:14

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.