daily pastebin goal
33%
SHARE
TWEET

Mary had a little lamb.

kylemikableh Nov 20th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Test
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         Scanner in = new Scanner(System.in);
  6.         String sentences = in.nextLine();
  7.         Scanner process = new Scanner(sentences);
  8.         Stack<String> jack = new Stack<String>();
  9.         String temp = "";
  10.        
  11.         Boolean isFirst = true;
  12.         while(process.hasNext())
  13.         {
  14.             String thisWord = process.next();
  15.             if(isFirst)
  16.             {
  17.                 thisWord = thisWord.toLowerCase();
  18.                 thisWord+=".";
  19.                 isFirst = false;
  20.             }
  21.             else if(thisWord.contains("."))
  22.             {
  23.                 isFirst = true;
  24.                 String cleanedString = thisWord.replaceAll("\\.", "");
  25.                 String firstLetter = cleanedString.substring(0,1);
  26.                 String restOfWord = cleanedString.substring(1, cleanedString.length());
  27.                 String newFirstLetter = firstLetter.toUpperCase();
  28.                 thisWord = newFirstLetter + restOfWord;
  29.             }
  30.             jack.push(thisWord);
  31.         }
  32.        
  33.         while(jack.size() > 0)
  34.         {
  35.             temp+=jack.pop() + " ";
  36.         }
  37.         System.out.println(temp);
  38.        
  39.     }
  40.  
  41. }
RAW Paste Data
Top