Write a java program to Print Message in different line
Please it's urgent
Answers
Answered by
1
Answer:
it is hopeful you i think
Explanation:
public class Main {
public static void main(String[] args) {
String s2 = "This is a text and we should print each word";
int i,j;
for (i = 0; i <= s2.length() - 1; i++){
if (s2.substring(i).startsWith(" ") || i == 0){
for (j = i + 1; j <= s2.length() - 1; j++){
if (s2.substring(j).startsWith(" ") || j == s2.length() - 1) { System.out.println(s2.substring(i, j));
i = j;
}
}
}
}
}
}
Output:
This
is
a
text
and
we
should
each
word
Similar questions