You are on page 1of 2

StringTokenizer Programs

1. Program to Encode the vowels :


import java.util.*;
class Encode
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a sentence");
String str=sc.nextLine().toUpperCase();
StringTokenizer st=new StringTokenizer(str);
while(st.hasMoreTokens())
{
String w=st.nextToken();
String e="";
for(int i=0;i<w.length();i++)
{
char ch=w.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
e=e+(char)(ch+2);
else
e=e+ch;
}
System.out.print(e+" ");
e="";
}
}
}
2. Program to count the number of Palindrome words:
import java.util.*;
class Palindrome
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a sentence");
String str=sc.nextLine().toUpperCase();
StringTokenizer st=new StringTokenizer(str);
int c=0;
while(st.hasMoreTokens())
{
String w=st.nextToken();
String rev="";
for(int i=0;i<w.length();i++)
{
char ch=w.charAt(i);
rev=ch+rev;
}
if(rev.equals(w))
c++;
rev="";
}
System.out.println("count="+c);
}
}

You might also like