0% found this document useful (0 votes)
21 views2 pages

Java StringTokenizer Programs

This document contains code for two programs that use StringTokenizer. The first program encodes all vowels in a sentence by incrementing their character code by 2. The second program counts the number of palindrome words in a sentence by reversing each word and comparing it to the original.

Uploaded by

Renee Thephail
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Java StringTokenizer Programs

This document contains code for two programs that use StringTokenizer. The first program encodes all vowels in a sentence by incrementing their character code by 2. The second program counts the number of palindrome words in a sentence by reversing each word and comparing it to the original.

Uploaded by

Renee Thephail
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

StringTokenizer Programs

1. Program to Encode the vowels :


import [Link].*;
class Encode
{
void main()
{
Scanner sc=new Scanner([Link]);
[Link]("enter a sentence");
String str=[Link]().toUpperCase();
StringTokenizer st=new StringTokenizer(str);
while([Link]())
{
String w=[Link]();
String e="";
for(int i=0;i<[Link]();i++)
{
char ch=[Link](i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
e=e+(char)(ch+2);
else
e=e+ch;
}
[Link](e+" ");
e="";
}
}
}
2. Program to count the number of Palindrome words:
import [Link].*;
class Palindrome
{
void main()
{
Scanner sc=new Scanner([Link]);
[Link]("enter a sentence");
String str=[Link]().toUpperCase();
StringTokenizer st=new StringTokenizer(str);
int c=0;
while([Link]())
{
String w=[Link]();
String rev="";
for(int i=0;i<[Link]();i++)
{
char ch=[Link](i);
rev=ch+rev;
}
if([Link](w))
c++;
rev="";
}
[Link]("count="+c);
}
}

You might also like