Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package Assign4;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Assignment4 {
  6.  
  7. public static void main(String args[]) {
  8.  
  9.  
  10. int countA = 1;
  11. int countB = 1;
  12.  
  13. Scanner sc = new Scanner(System.in);
  14.  
  15. System.out.println("Enter the number of players: ");
  16.  
  17. // Get player count
  18. int playerCount = sc.nextInt();
  19.  
  20. // Create string array with length of playerCount
  21. String[] playerNames = new String[playerCount];
  22.  
  23. // Get player names and store them in array
  24. for(int x = 0; x<playerNames.length; x++) {
  25. System.out.println("Enter player " + countA + "'s name: ");
  26. playerNames[x] = sc.next();
  27. countA++;
  28. }
  29.  
  30. // Print player names
  31. for(int y = 0; y<playerNames.length; y++) {
  32. System.out.println("Player " + countB + "'s name: " + playerNames[y]);
  33. countB++;
  34. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement