daily pastebin goal
59%
SHARE
TWEET

Term 2: Lesson 1 - Coding Activity

apez1 Dec 6th, 2018 65 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top