• Post Reply Bookmark Topic Watch Topic
  • New Topic

RE:String handling in java  RSS feed

 
Vidya Bhargavi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I have a string ...

string eg="Java is a interesting subject".

my output of the coding should be 131.....(Counting of the occurences of "J","a" like that the whole string)


Please send me a java coding for the above scenario.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
131? That seems pretty random.

Are you trying to get the length of a string? If so, have you checked the String Javadocs?
 
Vidya Bhargavi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


it was asked to me in an interview....


i need to use mark method...


please try and give me the coding na
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vidya Bhargavi wrote: please try and give me the coding na


well na, apply your own logic . how far you tried this? first come up with your logic,then we are here to help you
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vidya Bhargavi wrote:Please send me a java coding for the above scenario.

Vidya Bhargavi wrote:please try and give me the coding na

http://faq.javaranch.com/java/NotACodeMill
http://faq.javaranch.com/java/DoYourOwnHomework
 
Vidya Bhargavi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



I have given below the coding for the above scenario...


but i am getting "filenotfoundexception"......


...


Can please anyone help me out like how to solve that......

coding:-

import java.io.*;

class markmethod
{
public static void main(String args[]) throws Exception
{
File f=new File("D:/file/out.txt");
FileInputStream fis=new FileInputStream(f);
BufferedInputStream bis=new BufferedInputStream(fis);
int i;
while( (i=bis.read()) != -1 )
{
if( (char) i == '3' )
bis.mark(62);
}
// System.out.println();
// System.out.println((char)32);
bis.reset();

while( (i=bis.read()) != -1 )
{
System.out.print( (char) i );
}
}
}


 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is hard to read without CODE tags and with the incorrect capitalisation.
The answer to your question might be, "make sure the file sought exists."

And when you do, you will get another Exception. What on earth does mark(62) mean?
 
Jer Deras
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give a better example
wondered how you get 131
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!