Advertisement
dawciobiel

Untitled

Dec 18th, 2022
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Application {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Application app = new Application();
  8.  
  9.         String word = app.askUserFor("word");
  10.         String[] letters = word.split("");
  11.  
  12.         String stringOfColors = app.askUserFor("colors split by comma in hex value, ie: 084CFB,ADF3FD,F3FDAB and " + "press ENTER");
  13.         String[] colors = stringOfColors.split(",");
  14.  
  15.         System.out.println("\n" + app.doColorization(letters, colors));
  16.     }
  17.  
  18.     private String getNextColor(String[] colors, int idx) {
  19.         return colors[idx];
  20.     }
  21.  
  22.     private String askUserFor(String st) {
  23.         Scanner scanner = new Scanner(System.in);
  24.         System.out.println("Please input a " + st + " and press ENTER:");
  25.  
  26.         return scanner.next();
  27.     }
  28.  
  29.     private String doColorization(String[] letters, String[] colors) {
  30.         int idx = 0;
  31.         StringBuilder result = new StringBuilder();
  32.  
  33.         for (String l : letters) {
  34.             result.append(getNextColor(colors, idx) + l);
  35.             idx = idx + 1;
  36.             if (idx == colors.length) idx = 0;
  37.         }
  38.  
  39.         return result.toString();
  40.     }
  41. }
Tags: mindcraft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement