Created
January 3, 2017 07:16
-
-
Save KevinTyrrell/9f24316e6090c7b5959c6d6094b27eda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Make program which asks for student's names, | |
then when the user types "done", | |
prints them all out in the console window. | |
*/ | |
import java.util.LinkedList; | |
import java.util.Scanner; | |
public class Program | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner s = new Scanner(System.in); | |
//String[] ar = new String[100000]; | |
//int counter = 0; | |
LinkedList<String> list = new LinkedList<>(); | |
// list.get(150000000); <---- takes SUPER LONG | |
// ar[0]; <----- instant! | |
String input; | |
do | |
{ | |
System.out.print("Please enter your name: "); | |
input = s.nextLine(); | |
list.add(input); | |
//ar[counter] = input; | |
//counter++; | |
} while (input.equals("done") == false); | |
// Print out all the names | |
for (int i = 0; i < list.size(); i++) | |
{ | |
System.out.println(list.get(i)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment