0
我不斷收到錯誤「插入AssignmentOperator表達式以完成表達式」我的程序基本上是選擇一個動物所在的隨機位置。我正在寫arrary和變量,對吧? ??「插入AssignmentOperator表達式」錯誤JAVA
問題發生在if語句中;具體的代碼是giraffeLocation [r.nextInt(giraffeLocation.length)];
import java.util.Scanner;
import java.util.Random;
public class animaltracker {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
Random r = new Random();
char giraffe;
char rhino;
char hipopotamus;
String[] giraffeLocation;
giraffeLocation = new String[3];
giraffeLocation[0] = ("Africa");
giraffeLocation[1] = ("Russia");
giraffeLocation[2] = ("Germany");
System.out.println("Welcome to the animal tracker!");
try { Thread.currentThread().sleep(800); }
catch (Exception e) { }
System.out.println("Which animal shall we be tracking today?");
try { Thread.currentThread().sleep(800); }
catch (Exception e) { }
System.out.println("\nGiraffe?\nRhino?\nHipopotamus?");
String animal = s.nextLine();
if(animal.equalsIgnoreCase("giraffe")){
**giraffeLocation [r.nextInt(giraffeLocation.length)];**
System.out.println("Your giraffe is in, " + giraffeLocation);
}
}
}
它看起來像你忘記了實際_do_數組中的那個索引的值 –
_giraffeLocation [r.nextInt(giraffeLocation.length)] _你想在這裏實現什麼? –
@MattBall喜歡什麼? – user2548682