Java String programs: They are asked for more than 15 marks in the ICSE computer application class X
For java videos click
http://www.youtube.com/trushnatej

Write a program To extract letters of a word(String)
For example if the string is programs, the output will be p, r, o ,g, r, a, m in different lines.
import java.io.*;
class Extract
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a word");
String wrd= br.readLine();
int len=wrd.length();
for (int i=0;i<len;i++)
{
char ch=wrd.charAt(i);
System.out.println(ch);
}
}
}
Output:-
Enter a word
Computer
C
o
m
p
u
t
e
r
Write a program to extract words of a sentence.
import java.io.*;
class ExtractWord
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a sentence");
String str= br.readLine();
int len=str.length();
int d=0;
for (int i=0;i<len;i++)
{
char ch=str.charAt(i);
if(Character.isWhitespace(ch))
{
String temp=str.substring(d,i);
d=i;
System.out.println(temp.trim());
}
}
}
}
Enter a sentence
This is computer program
This
is
computer
program