String Programs part 5
String Programs part 5: solved Java program for ICSE Class 10 Computer Applications with complete BlueJ code, explanation and sample output.
- Write a program to extract words of a sentence and calculate the potential of the words, print the words with their potential(Potential is the sum of the ASCII values of each letter of the word)
import java.io.*;
class WordPotential
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a sentence");
String str= br.readLine();
str=str+" ";
str=str.toUpperCase();
int len=str.length();
int d=0; int sum=0;
System.out.println("Word "+ "\t" + "Potential" );
for (int i=0;i<len;i++)
{
char ch=str.charAt(i);
if(Character.isWhitespace(ch))
{
String temp=str.substring(d,i);
temp=temp.trim();
int len2=temp.length();
for(int j=0;j<len2;j++)
{
char ch1=temp.charAt(j);
sum+=(int)ch1;
}
System.out.println(temp+"\t "+sum);
sum=0;
d=i;
}
}
}
}
/*
Output:
Enter a sentence
This is India
Word Potential
THIS 312
IS 156
INDIA 357
*/2. Write a program to input a word and encrypt it. Each consonant of the word should be replaced with its next letter in the alphabet , and all the vowels will be converted to capital letters
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);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'I':
case 'E':
case 'O':
case 'U':
wrd=wrd.replace(ch,Character.toUpperCase(ch));
break;
default:
wrd=wrd.replace(ch,++ch);
break;
}
}
System.out.println(wrd);
}
}
/*
Output:
Enter a word
Program
QtOhtAn
*/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.