gpt4 book ai didi

Java:将信息从一个数组添加到另一个数组

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

我刚刚开始学习 Java,目标是为 Android 制作游戏。我正在参加在线类(class),其中为我提供了一项任务,然后进行某种评估。

这是我到目前为止所做的:

public String[] pie;
public Scanner x;
public String[] name;
public String[] name1;
public String[] name2;
public int[] year;
public int[] numb;
public String[] language;
public boolean[] read;
public int[] rating;

public void openfile(){
try{x = new Scanner(new File("Raamatukogu.txt"));}
catch(Exception e){
System.out.println("no file was found");}}

public void readfil(){
while(x.hasNext()){
String rida = x.nextLine();
pie = rida.split("#");
for(int i = 0; i < pie.length ; i++){

我想做的是将这样的内容添加到我的代码中,但是是自动化的:

name[0] = pie[0]
name1[0] = pie[1]
name2[0] = pie[2]
year[0] = pie[3]
numb[0] = pie[4]
language[0] = pie[5]
read[0] = pie[6]
rating[0] = pie[7]

name[1] = pie[8]
name1[1] = pie[9]
name2[1] = pie[10]
year[1] = pie[11]
numb[1] = pie[12]
language[1] = pie[13]
read[1] = pie[14]
rating[1] = pie[15]

name[2] = pie[16]
name1[2] = pie[17]
...}

提前谢谢您!

最佳答案

试试这个

int j=0;
for(int i=0;i<pie.length;i++){
name[j] = pie[0];
name1[j] = pie[1];
name2[j] = pie[2];
year[j] = pie[3];
numb[j] = pie[4];
language[j] = pie[5];
read[j] = pie[6];
rating[j] = pie[7];
j++;
}

关于Java:将信息从一个数组添加到另一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10366652/

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