bizzcuit

Spell Caster

Nov 28th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         String bla = in.nextLine();
  10.         String[] text = bla.split(" ");
  11.         String spell = "";
  12.         boolean hasLetters = true;
  13.         int counter = 0;
  14.  
  15.         while (hasLetters) {
  16.             for (int i = 0; i < text.length; i++) {
  17.                 if (text[i].length() != 0) {
  18.                     spell += text[i].charAt(text[i].length() - 1);
  19.                     text[i] = text[i].substring(0, text[i].length() - 1);
  20.                     if (text[i].length() == 0) {
  21.                         counter += 1;
  22.                     }
  23.                     if (counter == text.length) {
  24.                         hasLetters = false;
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.  
  30.         for (int i = 0; i < spell.length(); i++) {
  31.             char letter = spell.charAt(i);
  32.             int number = (int) letter;
  33.             if (number >= 97) {
  34.                 number -= 96;
  35.             } else {
  36.                 number -= 64;
  37.             }
  38.  
  39.             int newIndex = i + number;
  40.  
  41.             while (newIndex > spell.length() - 1) {
  42.                 newIndex -= spell.length();
  43.             }
  44.  
  45.             if(newIndex > i){
  46.                 spell = spell.substring(0, i) +
  47.                         spell.substring(i + 1, newIndex + 1) +
  48.                         letter +
  49.                         spell.substring(newIndex + 1);
  50.             } else if (newIndex < i){
  51.                 spell = spell.substring(0, newIndex) + letter + spell.substring(newIndex, i) + spell.substring(i + 1);
  52.             }
  53.         }
  54.         System.out.println(spell);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment