Mit einem scanner zu akzeptieren, String-input und speichern Sie in einem String-Array

Kann mir bitte jemand helfen. Ich habe getan, zahlreiche Suche, kann aber keine Lösung finden, überall.
Ich bin ein Anfänger mit Java und derzeit üben Sie einige code, während Sie auf eine Pause von college.

Ich versuche zu machen, ein Telefonbuch-Programm. Im moment bin ich versucht, einen neuen Kontakt hinzufügen, unten ist der code, den ich habe, aber ich bin nicht sicher, wie Sie Sie speichern, um die Informationen in einem array kann mir jemand ein paar Tipps bitte.

    import java.util.Scanner;

    public class addContact {
    public static void main(String [] args){

    //declare arrays
        String [] contactName = new String [12];
        String [] contactPhone = new String [12];
        String [] contactAdd1 = new String [12];
        String [] contactAdd2 = new String [12];

    //inputs
    String name = "";
    String phone = "";
    String add1 = "";
    String add2 = "";

    //method of taken input
    Scanner input = new Scanner(System.in);

    //while name field is empty display prompt etc.
    while (name.equals(""))
    {
    System.out.println("Enter contacts name: ");
    name = input.nextLine();
    name += contactName[];
    }


    while (add1.equals(""))
    {
    System.out.println("Enter contacts addressline1:");
    add1 = input.nextLine();
    add1 += contactAdd1[];
    }

    while (add2.equals(""))
    {
    System.out.println("Enter contacts addressline2:");
    add2 = input.nextLine();
    add2 += contactAdd2[];
    }

    while (phone.equals(""))
    {
    System.out.println("Enter contact phone number: ");
    phone = input.nextLine();
    phone += contactPhone[];
    }

    }   
}

InformationsquelleAutor Rachael | 2013-01-11

Schreibe einen Kommentar