
我写了一个程序来获取用户的地址详细信息并打印相同而不使用2 for循环,所以我使用函数add_show().但我收到错误,因为string []无法转换为字符串.返回添加;
public String add_show()
{
Scanner h=new Scanner(System.in);
System.out.println("Enter the number of address to deliver");
int n=h.nextInt();
String[] add=new String[n];
System.out.println("Enter the"+n+" of address to deliver");
for(int i=0;i<n;i++)
{
add[i]=h.next();
}
return add;
}
public void show()
{
System.out.println("Book name is "+B_name());
System.out.println("count "+department());
System.out.println("address is "+add_show());
}
Run Code Online (Sandbox Code Playgroud)
请更新,如何从函数中获取数组的返回值.
java ×1