0
   

IO question

 
 
Reply Mon 15 Jun, 2009 02:20 pm
/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./
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,083 • Replies: 1
No top replies

 
engineer
 
  2  
Reply Mon 15 Jun, 2009 02:24 pm
@Prateekr10,
If I understand the purpose of your code correctly, shouldn't this line increment i by one instead of by the length of the string?

Quote:
System.out.println(i+=s.length());

0 Replies
 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » IO question
Copyright © 2019 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 09/17/2019 at 08:54:27