Characters program in java
class FrequencyOfChar{
public static void main(String args[])
{
String st="hello Hi, Bolo Jara to";
int i,l,j,f=0;
char ch;
l=st.length();
st=st.toUpperCase();
for(i=65;i<=90;i++)
{
for(j=0;j<l;j++)
{
ch=st.charAt(j);
if(ch==(char)i)
f++;
}
System.out.println((char)i+" appears="+f);
f=0;
}
}
}
Java program to find total Vowels of words from a given sentence.
public class VowelFromWord
{
public static void main(String args[])
{
// Sentence taken
String st="the quick brown dog jumpe over a lazy fox";
String word=""; // initialize the variable word
int i,l,l1,j,v;
char ch,ch1;
st=st+" ";
l=st.length();
for(i=0;i<l;i++)
{
v=0;
ch=st.charAt(i);
if(ch!=' ')
{
word=word+ch; // picking the word
}
else
{
l1=word.length();
for(j=0;j<l1;j++)
{
ch1=word.charAt(j);
if(ch1=='a' || ch1=='e' || ch1=='i'|| ch1=='o' || ch1=='u')
v++; // calculating the vowel in the picked word
}
// printing the word with vowel
System.out.println(word+" contain " + v+" vowel");
word="";
}
}
}
}
Output
quick contain 2 vowel
brown contain 1 vowel
dog contains 1 vowel
jump contains 2 vowel
over contain 2 vowel
a contain 1 vowel
lazy contain 1 vowel
fox contains 1 vowel
Java program to find a total number of characters from a given sentence.
import java.io.*;
public class CharacterFinder
{
public static void main(String args[])throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
char ch,ch1;
int i,l,c=0;
String st;
System.out.print("Enter String :");
st=br.readLine();
l=st.length();
System.out.print("Enter a Character :");
ch1=(char)br.read();
for(i=0;i<l;i++)
{
ch=st.charAt(i);
if(ch==ch1)
c++;
}
System.out.println("Total :"+c);
}
}
Output
Enter String: The quick brown fox
Enter a Character: q
Total: 1
Enter String: He is a good boy. He is doing a good job.
Enter a Character :o
Total: 7
Java program to find Word pattern by giving a position
import java.util.*;
public class StringPattern
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String st;
int i,l,j,n;
char ch;
System.out.println("Enter a String and position:");
st=sc.next();
n=sc.nextInt();
l=st.length();
for(i=0;i<l-n;i++)
{
for(j=0;j<l-n;j++)
{
System.out.print(" ");
}
ch=st.charAt(i);
System.out.println(ch);
}
System.out.println(st);
for(i=0;i<l-n;i++)
{
for(j=0;j<l-n;j++)
{
System.out.print(" ");
}
ch=st.charAt(i+n);
System.out.println(ch);
}
}
}
Output
HELLO
3
H
E
HELLO
L
O
Enter a String and position:
EDUCATION
4
E
D
U
C
A
EDUCATION
A
T
I
O
N
Visit also