gpt4 book ai didi

java - int 数组或字符串数​​组或我错了

转载 作者:行者123 更新时间:2023-12-01 19:22:55 24 4
gpt4 key购买 nike

我试图将日期和时间放入数组中,但我收到错误,因为我不能将日期/时间或只是变量,我尝试将 int 数组更改为字符串,但我收到错误,它无法解析为变量

private static void listM() {
// TODO Auto-generated method stub
System.out.println("Here is the list of Movie(s) to select from," // gives user a list of movies to choose from
+ "\nPlease enter its respective ID:\n"
+ "1. Captain America\t|2. Toy Story\t|3. Jumanji\n4. Black Panther\t|"
+ "5. Green Lantern\t|6. Detective Pikachu\n7. Thor\t|8. 2012\t|9. Geostorm\n");

System.out.println("");
Scanner scanner = new Scanner(System.in); //use scanner to get ID of Movie

System.out.print("Input the ID of the Movies to view their information: ");
int idmovie = scanner.nextInt();

String[] movie = new String[9]; //make an array to store the movie information
movie[0] = test;
movie[1] = Captain;
movie[2] = xxx;
movie[3] = xxx;
movie[4] = xxx;
movie[5] = xxx;
movie[6] = xxx;
movie[7] = xxx;
movie[8] = xxx;

最佳答案

您需要在字符串周围加上引号。当您编写 movie[0] = test; 时,java 会尝试将名为 test 的变量的值放入电影数组中。因为您没有定义名为 test 的变量,Java 将抛出您收到的错误。

以下是您可能想要定义数组的方式:

movie[0] = "test";

关于java - int 数组或字符串数​​组或我错了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59340741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com