Guest User

Untitled

a guest
May 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. class JumbleWords{
  4.   public static void main(String [] args){
  5.   //Get and read text
  6.     System.out.print("Enter some text:\n");
  7.     Scanner getText= new Scanner(System.in);
  8.  
  9.     while (getText.hasNextLine()){
  10.       Scanner line= new Scanner(getText.nextLine());
  11.       //Get next word from line
  12.       while (line.hasNext()){
  13.         String word= line.next();
  14.         int wordLength= word.length();
  15.         char [] letters= word.toCharArray();
  16.  
  17.           //Prints every other letter starting with the second
  18.         for (int x= 1; x < wordLength; x+=2){
  19.           System.out.print(letters[x]);
  20.         }
  21.           //Prints every other letter starting with the first
  22.         for (int x= 0; x < wordLength; x+=2){
  23.           System.out.print(letters[x]);
  24.         }
  25.         System.out.print(" "); //Add space between words
  26.       }
  27.       System.out.println();  //end line
  28.       break;
  29.     }
  30.   }
  31. }
Add Comment
Please, Sign In to add comment