Advertisement
Guest User

List and Arrays

a guest
Sep 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package listtest;
  2. /**
  3.  *
  4.  * @author RubenLaptop
  5.  */
  6. import java.util.List;
  7. import java.util.ArrayList;
  8. import java.util.Scanner;
  9. public class ListTest {
  10.  
  11.     public static void main(String[] args) {
  12.        
  13.         String itemOne;
  14.         String itemTwo;
  15.         Scanner userInput = new Scanner (System.in);
  16.        
  17.         List<String> groceryList = new ArrayList<>();
  18.         System.out.println("Please enter in a grocery list item:");
  19.         groceryList.add(itemOne = userInput.next());
  20.         System.out.println("Please enter a second entry:");
  21.         groceryList.add(itemTwo = userInput.next());
  22.        
  23.         System.out.println("The second item on the list is "+groceryList.get(1)+".");
  24.         System.out.println("The first item on the list is "+groceryList.get(0)+".");
  25.        
  26.     }
  27.    
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement