Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String sentence = scanner.nextLine();
- String[] words = sentence.split(" ");
- String newWord = "";
- boolean isTrue = true;
- int freeWords = 0;
- while (isTrue) {
- for (int w = 0; w < words.length; w++) {
- if (!(words[w].isEmpty())) {
- newWord += words[w].charAt(words[w].length() - 1);
- words[w] = words[w].substring(0, words[w].length() - 1);
- } else {
- freeWords++;
- }
- if (freeWords == words.length) {
- isTrue = false;
- }
- }
- }
- System.out.println(newWord);
- int ascii = 0;
- int newIndex = 0;
- // List<Character> newSeq = new ArrayList<Character>(100);
- // System.out.println(newSeq.size());
- // for (int i = 0; i <newWord.length() ; i++) {
- // newSeq.add(i, newWord.charAt(i)) ;
- // }
- for (int i = 0; i <newWord.length() ; i++) {
- char letter = newWord.charAt(i);
- ascii = (int) letter;
- if (ascii >= 97) {
- ascii -= 96;
- } else {
- ascii -= 64;
- }
- newIndex = ascii + i ;
- while (newIndex > newWord.length() - 1) {
- newIndex -= newWord.length();
- }
- newWord = newWord.substring(0, newIndex) + newWord.charAt(i) + newWord.substring(newIndex);
- }
- // for (int i = 0; i <newWord.length() ; i++) {
- // newSeq.set(newIndex, newWord.charAt(i));
- // }
- System.out.println(newWord);
- }
- }
- v
Advertisement
Add Comment
Please, Sign In to add comment