Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String bla = in.nextLine();
- String[] text = bla.split(" ");
- String spell = "";
- boolean hasLetters = true;
- int counter = 0;
- while (hasLetters) {
- for (int i = 0; i < text.length; i++) {
- if (text[i].length() != 0) {
- spell += text[i].charAt(text[i].length() - 1);
- text[i] = text[i].substring(0, text[i].length() - 1);
- if (text[i].length() == 0) {
- counter += 1;
- }
- if (counter == text.length) {
- hasLetters = false;
- }
- }
- }
- }
- for (int i = 0; i < spell.length(); i++) {
- char letter = spell.charAt(i);
- int number = (int) letter;
- if (number >= 97) {
- number -= 96;
- } else {
- number -= 64;
- }
- int newIndex = i + number;
- while (newIndex > spell.length() - 1) {
- newIndex -= spell.length();
- }
- if(newIndex > i){
- spell = spell.substring(0, i) +
- spell.substring(i + 1, newIndex + 1) +
- letter +
- spell.substring(newIndex + 1);
- } else if (newIndex < i){
- spell = spell.substring(0, newIndex) + letter + spell.substring(newIndex, i) + spell.substring(i + 1);
- }
- }
- System.out.println(spell);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment