System.out.println("I\nam\na\nboy");
System.out.println("I am a boy".replaceAll("\\s+","\n"));
System.out.println("I am a boy".replaceAll("\\s+",System.getProperty("line.separator"))); // portable way
//The class name should be the same as your Java-file and directory name.
class iAmABoy {
//Create a variable number of String-type arguments, "strs"; this is a useful line of code worth memorizing.
public static void nlSeparated(String... strs) {
//Each argument is an str that is printed.
for (String str : strs) {
System.out.println(str);
}
}
public static void main(String[] args) {
//This loop uses 'args' . 'Args' can be accessed at runtime. The method declaration (above) uses 'str', but the method instances (as seen below) can take variables of any name in the place of 'str'.
for (String arg : args) {
nlSeparated(arg);
}
//This is a signature. ^^
System.out.print("\nThanks, Wolfpack08!");
}
}
public class HelloWorld{
public static void main(String []args){
String input = "I am a boy";
String[] opuput = input.split(" ");
for (int i = 0; i < opuput.length; i++)
System.out.println(opuput[i]);
}
}