我不知道我的编码是否有效,甚至正确,但我想输入姓名、地址和电话号码。然后我想让输入从输入数组中找到匹配项,并使用相同的索引号打印相应的信息。
import java.util.*;
public class NameAddress {
public static void main(String[] args) {
Scanner ui = new Scanner(System.in);
System.out.println("Welcome to the name collecting database");
String []names = new String[5];
String []address = new String[5];
String []phone = new String [5];
int count =0;
while (count<=5)
{
System.out.println("Please enter the name you would like to input");
names[count] =ui.next();
System.out.println("Name has been registered into Slot "+(count+1)+" :"+Arrays.toString(names));
System.out.println("Please enter the address corresponding with this name");
ui.nextLine();
address[count] = ui.nextLine();
System.out.println(names[count]+" has inputted the address: "+address[count]+"\nPlease input your phone number");
phone[count]=ui.nextLine();
System.out.println(names[count]+"'s phone number is: "+phone[count]+"\nWould you like to add a new user? (Yes or No)");
if (ui.next().equals("No"))
{
System.out.println("Please enter a name to see matched information");
String name = ui.next();
if(name.equals(names[count]))
{
System.out.println("Name: "+names[count]+"\nAddress: "+address[count]+"\nPhone: "+phone[count]);
}
count=6;
}
count++;
}
}
}