Advertisement
StefanTobler

Lesson 30 Activity

Nov 4th, 2016
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. /*
  2.  * Lesson 30 Coding Activity
  3.  * Due to a problem with a scanner an array of words was created
  4.  * with spaces in incorrect places. Write the code to process the
  5.  * list of words and trim any spaces out of the words.
  6.  *
  7.  * So if the list contains:
  8.  *      {"every", " near ing ", " checking", "food ", "stand", "value "}
  9.  *
  10.  * It should be changed to hold:        
  11.  *      {"every", "nearing", "checking", "food", "stand", "value"}
  12.  *        
  13.  * Note that this activity does not require you to print anything.
  14.  * Your code should end with the array list still declared and
  15.  * containing the resulting words.
  16.  *
  17.  */
  18.  
  19.  
  20. import java.util.Scanner;
  21.  
  22. class Lesson_30_Activity {
  23.      
  24.    /*
  25.     * Your code should end with the following array modified as the
  26.     * instructions above specify. You may modify the elements in
  27.     * this list but make sure you do not add or remove anything from it.
  28.    */
  29.     public static String [] list = {"every", " near ing ", " checking", "food ", "stand", "value "};
  30.  
  31.     public static void main(String[] args)
  32.      {
  33.       for (int i = 0; i < list.length; i++)
  34.       {
  35.         list[i] = list[i].replaceAll("\\s", "");
  36.         System.out.println(list[i]);
  37.       }
  38.      
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement