Advertisement
HarrJ

B8 Day 15 Method 2

Sep 27th, 2022
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package mattroseb8wk3;
  2.  
  3. public class Day15B {
  4.     public static void main(String[] args) {
  5.         Day15B callMe = new Day15B();
  6.         String name = "ash williams";
  7.         String address = "cabin in the woods";
  8.         String likes = "chainsaws and shotgun";
  9.         String dislikes = "zombies";
  10.        
  11.         System.out.print(callMe.generateTitleCase(name));
  12.         System.out.println("lives at a " + callMe.generateTitleCase(address));
  13.         System.out.print(callMe.generateTitleCase(name) + "likes ");
  14.         System.out.print(callMe.generateTitleCase(likes) +"and hates ");
  15.         System.out.println(callMe.generateTitleCase(dislikes));
  16.     }
  17.  
  18.    
  19.     public String generateTitleCase(String txtIn) {
  20.         String txtOut = "";
  21.         String[] txtArray = txtIn.split(" ");
  22.         for (String str : txtArray) {
  23.             txtOut += str.toUpperCase().substring(0,1);
  24.             txtOut += str.toLowerCase().substring(1);
  25.             txtOut += " ";
  26.         }
  27.         return txtOut;
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement