Java examples for Language Basics:for
A for loop that fills an array of player names with strings entered by the user.
import java.util.Scanner; public class Main { public static void main(String[] args) { int count = 10; String[] players = new String[count]; Scanner sc = new Scanner(System.in); for (int i = 0; i < count; i++) { System.out.print("Enter player name: "); players[i] = sc.nextLine(); // sc is a Scanner }//from w ww .j a va 2 s. c o m } }