Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created September 7, 2012 10:43
Show Gist options
  • Save DominicFinn/3665033 to your computer and use it in GitHub Desktop.
Save DominicFinn/3665033 to your computer and use it in GitHub Desktop.
Splits a string and puts spaces in it
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String answer = "";
String result = "";
char[] arrayOfCharacters;
System.out.println("Give me a string and ill put spaces in it");
answer = input.nextLine();
arrayOfCharacters = answer.toCharArray();
for(int x = 0; x < arrayOfCharacters.length; x++) {
result = result + arrayOfCharacters[x] + " ";
}
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment