armandocat

Coding challenge #1

Sep 5th, 2017
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. class Main {
  2.  
  3.   /*
  4.    * Example: 'abc def' --> 'fed cba'
  5.    */
  6.   public static void reverseAll(char[] text) {
  7.    
  8.   }
  9.  
  10.   /*
  11.    * Example: 'abc def' --> 'cba fed'
  12.    */
  13.   public static void reverseWords(char[] text) {
  14.    
  15.   }
  16.  
  17.   /***************************/
  18.   /***************************/
  19.   /* DO NOT CHANGE DOWN HERE */
  20.   /***************************/
  21.   /***************************/
  22.  
  23.   public static void solve(String text) {
  24.     System.out.println("Reversing string:                   " + text);
  25.  
  26.     char [] reversedAll = text.toCharArray();
  27.     reverseAll(reversedAll);
  28.     System.out.println(String.format("Result after reversing all:         %s", new String(reversedAll)));
  29.  
  30.     char [] reversedWords = text.toCharArray();
  31.     reverseWords(reversedWords);
  32.     System.out.println(String.format("Result after reversing the words:   %s", new String(reversedWords)));
  33.    
  34.     System.out.println();
  35.   }
  36.  
  37.   public static void main(String[] args) {
  38.     solve("abc def");
  39.     solve("This is a sentence I want to reverse");
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment