Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by danie on 3/1/2017
- */
- //Daniel Lawson powerpoint exercise
- import java.util.*;
- public class Exercises {
- public static void main(String[] args){
- ArrayList<String> list = new ArrayList<>(Arrays.asList("foodS","more","tests","food","weird"));//make an array
- System.out.println("Original: " + list.toString()); // print the first array
- reverse(list); // call the reverse method
- System.out.println("Reversed order: " +list.toString()); // print out the array after it is reversd
- capitalizePlurals(list); // call the method for capitalizing the plurals
- System.out.println("Capitalized plurals: " + list.toString()); // print the array after the plurals are capitalized
- removePlurals(list); // call the method to remove all plurals
- System.out.println("Removed Plurals: " + list.toString()); // print out the array after plurals are removed
- }
- public static void reverse(ArrayList<String> list){
- for(int i = list.size()-1; i >0;i--){
- String word = list.get(0); // store the first word in the array
- list.remove(0); // remove it
- list.add(i,word); // add it to the last place minus what number after the first one it is
- }
- }
- public static void capitalizePlurals(ArrayList<String> list){
- for(int i = 0; i<list.size();i++){
- String s = list.get(i); // get a word
- if(s.toLowerCase().endsWith("s")){ // if it ends with a s
- list.set(i,s.toUpperCase()); // set it to be uppercase
- }
- }
- }
- public static void removePlurals(ArrayList<String> list){
- for(int i = 0; i<list.size(); i++){
- if(list.get(i).toLowerCase().endsWith("s")){ // if a word ends with s
- list.remove(i); // remove it
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment