public class S {
public static void main(String[] args) {
String s = “hi friends how are you”;
int count = 0, k = 0;
List a = new ArrayList();
char c[] = s.toCharArray();
for (int j = 0; j < s.length(); j++) {
if (c[j] == ' ') {
String z = s.substring(count, j);
a.add(z);
count = j + 1;
}
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String big =”hello how are you?”;
ArrayList list = new ArrayList();
String temp =””;
for(int i=0; i<big.length(); i++){
char t =big.charAt(i);
if( t == ' '){
list.add(temp);
temp ="";
continue;
}
temp =temp + t;
}
list.add(temp);
for i in a:
if i!=” “:
print(i,end=””) elif i==” “:
print() a=input()
read_s(a)
import java.util.ArrayList;
import java.util.List;
public class S {
public static void main(String[] args) {
String s = “hi friends how are you”;
int count = 0, k = 0;
List a = new ArrayList();
char c[] = s.toCharArray();
for (int j = 0; j < s.length(); j++) {
if (c[j] == ' ') {
String z = s.substring(count, j);
a.add(z);
count = j + 1;
}
}
System.out.println(a);
}
}
strr=’I am Gourav Raghuwanshi’
l=[]
s=”
for ele in strr:
if(ele==’ ‘):
l.append(s)
s=”
else:
s+=ele
l.append(s)
print(l)
in python code, there is some wrong
#include
int main()
{
char arr[100];
int k;
scanf(“%[^\n]%*c”,arr);
k=strlen(arr);
for(int i=0;i<k;i++)
{
if(arr[i]!=' ')
printf("%c",arr[i]);
else
printf("\n");
}
return 0;
}
#python
def read_s(a):
for i in a:
if i!=” “:
print(i,end=””)
elif i==” “:
print()
a=input()
read_s(a)
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String big =”hello how are you?”;
ArrayList list = new ArrayList();
String temp =””;
for(int i=0; i<big.length(); i++){
char t =big.charAt(i);
if( t == ' '){
list.add(temp);
temp ="";
continue;
}
temp =temp + t;
}
list.add(temp);
for(int j=0; j<list.size(); j++){
System.out.println(list.get(j));
}
}
}
Python code :
string = input()
for i in string.split():
print(i)