Hello everyone, below is my code;
import java.util.Scanner; public class user1{ public static void main(String args[]) { Scanner input = new Scanner(System.in); String array[] = new String [15];//array for name only int x; do{ //store name System.out.println("Please enter your name below"); name(array); displayname(array); System.out.println("To exit, press 5; to contiue press any other number"); x=input.nextInt(); }while(x!=5); { System.out.println("end"); } }//end main public static void name(String a[]) { Scanner input = new Scanner(System.in); int i=0; a[i] = new Scanner (System.in).nextLine(); i=i+4; }//end method public static void displayname(String g[]) { //look here if issues on 2nd user, 3rd etc. int i=0; System.out.print("|"+ g[i]+ "|"); } }//end class
My problem is that when I add a new string name, the previous string name is replaced. I need to somehow increment my int variable' i' inside my static method named 'displayname', however everytime that method is called, 'i' is set to zero...Please help!! Thankyou