Astonishing Java String Programs part-III
Java String Programs part-III: solved Java program for ICSE Class 10 Computer Applications with complete BlueJ code, explanation and sample output.
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
For more string programs
Beautiful String programs in java part-II
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.