gpt4 book ai didi

java - 无法从 int[] 转换为 int?

转载 作者:行者123 更新时间:2023-11-30 07:44:01 25 4
gpt4 key购买 nike

我对一般编程很陌生,我一直在尝试为我的计算机科学类(class)用 java 构建一个系统,但在 eclipse 中收到错误“无法从 int[] 转换为 int”。

public static ArrayList<Book> CreateBooksArrayList(){
int[] id = {1,2,3,4,5};
String[] bookTitle = {"book1", "book2", "book3", "book4", "book5"};
String[] authorName = {"author1", "author2", "author3", "author4", "author5"};
double[] bookReleaseYear = {123,456,789,987,654};
int[] numOnLoan = {1,2,2,3,4};
int[] numInStock = {5,5,5,5,5};


int bID = -1;
String bTitle = null;
String aName = null;
double bRelease = -1;
int nLoan = -1;
int nStock = -1;

ArrayList<Book> Books = new ArrayList<Book>();
for (int i = 0; i<6; i++){
bID = id[i];
bTitle = bookTitle[i];
aName = authorName[i];
bRelease = bookReleaseYear[i];
nLoan = numOnLoan;
nStock = numInStock;
Books.add(new Book(bID, bTitle, aName, bRelease, nLoan, nStock));

我尝试寻找答案,但我似乎找不到与此确切问题相关的任何链接。预先感谢您的帮助!

最佳答案

您忘记了 for 循环中 numOnLoannumInStock[i] 部分。将它们都更改为包含 [i]

nLoan = numOnLoan[i];
nStock = numInStock[i];

关于java - 无法从 int[] 转换为 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34182927/

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