- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不断收到错误“插入赋值运算符表达式来完成表达式”我的程序基本上是选择动物所在的随机位置。我也正在编写数组和变量,对吗???
问题出现在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/
for (int iI = 4; iI > 0; iI--) faAmount[iI] - faAmount[iI - 1]; 这是它所在的代码。我该如何解决这个问题? 最佳答案 也许你忘记了等号
import java.util.logging.Logger; //includes not sure if I am missing one. import java.math.*; //incl
我正在尝试修复很久以前为 Craftbukkit 编写的插件, 但我对一个部分感到困惑。我在 Google 上搜索时运气不佳,我问过其他 Java 开发人员只是听说我不应该使用 for 循环,因为它相
这个问题已经有答案了: insert "Assignment Operator Expression" to complete Expression (1 个回答) 已关闭10 年前。 我不断收到错误
我在一个 Java 项目中有一个类,它包含一个二维值数组,并提供了与之交互的有用方法。它使用 Location 对象(仅存储两个值)访问映射中的点并返回值。它有一个方法 isValid(),用于检查
AssignmentExpression 的 EcmaScript 语法指定以下内容: AssignmentExpression : ConditionalExpression Yie
我正在学习 java 但遇到了这个问题,我正在编写一个简单的代码但是这个错误再次出现有人可以帮助我解决我做错了什么吗? public String alarmClock(int day, boolea
我有一些代码,如下所示: int batchPosition = new Integer(batchBegin); for (batchPosition;batchPosition<=batchEnd
在 iterator.hasNext() 中,显示错误。 iterator.hasNext() 中标记“<”存在语法错误,AssignmentOperator 无效 JSONArray build;
我现在正在学习如何使用 lambda 表达式,我看过一些带有简单示例的教程: (int x) -> x + 5; 但是我的编译器显示这个错误: Syntax error, insert "Assign
我正在自学 Java,当我在 Eclipse 中运行剪贴簿中的代码时遇到此错误: Syntax error, insert "AssignmentOperator Expression" to com
我是一名优秀的程序员,十分优秀!