Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- class JumbleWords{
- public static void main(String [] args){
- //Get and read text
- System.out.print("Enter some text:\n");
- Scanner getText= new Scanner(System.in);
- while (getText.hasNextLine()){
- Scanner line= new Scanner(getText.nextLine());
- //Get next word from line
- while (line.hasNext()){
- String word= line.next();
- int wordLength= word.length();
- char [] letters= word.toCharArray();
- //Prints every other letter starting with the second
- for (int x= 1; x < wordLength; x+=2){
- System.out.print(letters[x]);
- }
- //Prints every other letter starting with the first
- for (int x= 0; x < wordLength; x+=2){
- System.out.print(letters[x]);
- }
- System.out.print(" "); //Add space between words
- }
- System.out.println(); //end line
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment