suryavattikuti
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class WithOutSplit1
{
public static void main(String []args)
{
String info="This is a pen";
String res=info.replace(" ","\n");
System.out.println(res);
}
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
import java.io.*;
import java.util.*;
class Split {
public static void main(String[] args) {
int j=0;
char word[]=new char[10];
ArrayList<String> list=new ArrayList<>();
Scanner sc=new Scanner(System.in);
System.out.println("enter the sentence");
String s=sc.nextLine();
char[] c=s.toCharArray();
for (int i=0;i<c.length ;i++ ){
if (c[i]==' '){
list.add(new String(word));
j=0;
}
else{
word[j]=c[i];
j++;
}
}
list.add(new String(word));
for (String s1:list )
System.out.println(s1);
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
- suryavattikuti September 30, 2014