I'm trying to create a program which adds 10 names to an array list with a method that receives the names and prints them


12
views
0
3 months ago by
Anonymous
public class Arrays {


public static void main(String[] args) {
String[] names;
Scanner scan = new Scanner(System.in);
names = new String [10];


System.out.println("Enter 10 names: ");
for (int i = 0; i < names.length; i++){
names[i] = scan.nextLine();


ArrayList<String> nameArray = new ArrayList<>(Arrays.asList(names[i]));


arrayMethod(nameArray);
}


}

private static void arrayMethod(ArrayList<String> nameArray) {
for (String a : nameArray)
{

System.out.printf( "%s",a);
}
}
}
This is the output I'm getting when entering 10 names. Would anyone mind explaining why?
Enter 10 names:
bob
bobsteve
stevecarl
carljohn
johnnancy
nancyrich
richnate
natejosh
joshmatt
mattbecca
becca
Community: Java
Please login to add an answer/comment or follow this question.

Similar posts:
Search »
  • Nothing matches yet.