import java.io.*;
public class count
{
public static void main(String args[])
{
char alphabets[] =
{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','
z'};
int[] nalphabets = new int[26];
int i=0;
String s;
try
{
BufferedReader b2= new BufferedReader(new FileReader("2.txt"));
while((s=b2.readLine())!=null)
{
System.out.println(s);
for(int j=0;j<s.length();j++)
{
/*if(s.charAt(j)>=97 && s.charAt(j)<=122)
System.out.println(i+=s.length());
}*/
char ch = s.charAt(j);
for(int n=0;n < alphabets.length;n++)
{
if(ch == alphabets[n])
nalphabets[n] = nalphabets[n]+1;
}
}
}
b2.close();
}
catch(IOException o)
{
o.printStackTrace();
}
for(i=0;i<alphabets.length;i++)
{
System.out.println("The no of "+alphabets[i]+" alphabet in the file
are "+nalphabets[i]);
}
}
}
On Jun 16, 1:37 am, ρ Я д Ŧ έ e Қ ....Me |\|0T ThaT BaDD***
<[email protected]> wrote:
> /i want to count the no of alphabets from a to z in a file. The file is
> "2.txt" and its contents are as under:
>
> prateek
> rawal
> manit
>
> /
>
> import java.io.*;
>
> public class count
> {
> public static void main(String args[])
> {
>
> int i=0;
> String s;
> try
> {
>
> BufferedReader b2= new BufferedReader(new FileReader("2.txt"));
> while((s=b2.readLine())!=null)
> {
> System.out.println(s);
> for(int j=0;j<s.length();j++)
> {
> if(s.charAt(j)>=97 && s.charAt(j)<=122)
> System.out.println(i+=s.length());}
> }
> b2.close();
> }
>
> catch(IOException o)
> {
> o.printStackTrace();}
>
> System.out.println("The no of alphabets in the file are"+i);
>
> }
> }
>
> /There is no compilation error but it gives wrong output....please tell me
> what is the problem./
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---