Advertisement
Guest User

qqq

a guest
Apr 5th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package ex2;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.ArrayList;
  6. import java.util.Scanner;
  7.  
  8. public class Ayy {
  9.  
  10.     public static void main(String[] args) throws FileNotFoundException {
  11.         ArrayList<String> allWords = new ArrayList<String>();
  12.         Scanner input = new Scanner(new File("devoir1/ex2/proust.txt"));
  13.        
  14.         while(input.hasNext())
  15.         {
  16.             String word = input.next();
  17.             allWords.add(word);
  18.         }
  19.        
  20.         //1)
  21.         for(String word : allWords)
  22.             System.out.print(word+" ");
  23.        
  24.         System.out.println();
  25.        
  26.         //2)
  27.         for(int i=0;i<allWords.size();i++) {
  28.             for(int j=0;j<allWords.get(allWords.size()-i-1).length();j++)
  29.              System.out.print(allWords.get(allWords.size()-i-1).charAt(allWords.get(allWords.size()-i-1).length()-j-1));
  30.             System.out.print(" ");
  31.         }
  32.        
  33.         System.out.println();
  34.        
  35.         //3)
  36.         for(String word : allWords)
  37.         {
  38.             if(word.endsWith("s"))
  39.             {
  40.                 System.out.print(word.toUpperCase()+" ");
  41.                 continue;
  42.             }
  43.             System.out.print(word+" ");
  44.         }
  45.        
  46.         System.out.println();
  47.        
  48.         //4)
  49.         for(String word : allWords)
  50.         {
  51.             if(word.endsWith("s"))
  52.                 continue;
  53.             System.out.print(word+" ");
  54.         }
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement