Advertisement
apez1

Term 2: Lesson 1 - Coding Activity

Dec 6th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package project;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5. import java.math.*;
  6.  
  7. public class newTest {
  8.    
  9.  
  10.     public static void main(String[] args) {   
  11.  
  12.             Scanner input = new Scanner(System.in);
  13.             System.out.println("Please enter words, enter STOP to stop the loop.");
  14.            
  15.             String word = "";
  16.              
  17.             ArrayList <String> words = new ArrayList <String>();
  18.          
  19.             while (!word.equals("STOP")) {
  20.               word = input.nextLine();
  21.               words.add(word);
  22.            
  23.             }
  24.            
  25.             words.remove(words.size()-1);
  26.            
  27.             System.out.println(words.size());          
  28.             System.out.println(words);
  29.            
  30.             if (words.size()>2){
  31.               words.remove(words.size()-1);
  32.               words.remove(0);
  33.             }
  34.            
  35.             System.out.println(words);
  36.            
  37.           }
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement