我写了一个简单的对象数组,它需要五个字符串。我想要做的是使用for循环创建位置0和1的对象数组中的条目。然后创建一个文件夹,其中包含位置0的文本文件,并创建一个文件夹,其中包含一个文本文件的位置1.预期结果
folder0-> 0.txt
文本文件内容
Jeremey 12男120 120
有人12女100 100folder1-> 1.txt的
文本文件内容
Jeremey 12男120 120
有人12女100 100以下是已编写的代码示例。
对象数组类:
public class Info
{
private String Name;
private String age;
private String Gender;
private String Height;
private String weight;
Info(String Name, String age, String Gender, String Height, String weight)
{
this.Name = Name;
this.age = age;
this.Gender = Gender;
this.Height = Height;
this.weight = weight;
}
public String getName()
{
return this.Name;
}
public String getAge()
{
return this.age;
}
public String getGender()
{
return this.Gender;
}
public String getHeight()
{
return this.Height;
}
public String getWeight()
{
return this.weight;
}
}
主要课程:
import java.util.*;
public class UseInfo
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);
Info infor[] = new Info[2];
for(int i = 0; i < 2; i++)
{
System.out.println("Please enter Name: ");
String name = in.nextLine();
System.out.println("Please enter age: ");
String age = in.nextLine();
System.out.println("Please enter Gender: ");
String gender = in.nextLine();
System.out.println("Please enter Height: ");
String height = in.nextLine();
System.out.println("Please enter Weight: ");
String weight = in.nextLine();
infor[i] = new Info(name, age, gender, height, weight);
}
for(int k = 0; k < infor.length; k++)
{
System.out.println("Name : " + infor[k].getName() + " Age : " + infor[k].getAge() + " Gender : " + infor[k].getGender() + " Height : " + infor[k].getHeight() + " Weight : " + infor[k].getWeight() );
}
}
}
我无法弄清楚如何从数组中获取信息并将其传递到文件并将文件存储在文件夹中。