java - "Insert AssignmentOperator expression"JAVA错误

标签 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 );
                }







        }
    }

最佳答案

您实际上并没有将随机位置的查找存储在任何地方,您想要这样的东西:

String tmp = giraffeLocation [r.nextInt(giraffeLocation.length)];

System.out.println("Your giraffe is in, " + tmp );

关于java - "Insert AssignmentOperator expression"JAVA错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17461396/

相关文章:

java - 为同一个 Titan Graph 创建多个实例

java - 在表中插入记录时MySql中查询空异常

java - 是否可以将对象从对象重新键入为整数

java - TextViews 在 for 循环中更改文本

java - 如何在android中使用achartengine对齐到图表中心?

java - MainActivity 泄露了最初在此处添加的窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0

java - 如何处理具有相同 catch block 的解析数字?

java - 修复找不到符号 mInterstitialAd = new InterstitialAd(this);符号 : variable mInterstitialAd location: class Ads

java - 如何将对象列表设置为 Vaadin 8 组合框

java - 如何使用 jsoup 检查 HTML 元素的类型