gpt4 book ai didi

java - 如何使扫描仪变量成为数组?

转载 作者:行者123 更新时间:2023-12-01 23:08:49 25 4
gpt4 key购买 nike

我怎么可能做到这一点?我正在尝试执行此操作,但它说参数是字符串,并且需要 string[]

这是我的代码:

import java.util.Scanner;

public class Launch {

public static String[] josh = {
"Josh", "mcMc", "16", "grade 11"
};
public static void main(String[] args) {
Scanner sc = new Scanner(System. in );
System.out.print("Please enter the first name of the person you would love to know about : ");
String hisName = sc.next();
printSomeInfoAbout(hisName);
}

public static void printSomeInfoAbout(String[] name) {

System.out.println("My name is " + name[0] + " " + name[1] + ". I am " + name[2] + " " +
"Years old and I am currently in " +
name[3] + ".");
}
}

最佳答案

也许这就是您所需要的:

String[] hisName=new String[4]; 
for(int i=0;i<hisName.length;i++){
hisName[i]=sc.nextLine();
}
printSomeInfoAbout(hisName);

关于java - 如何使扫描仪变量成为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22342663/

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