• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RE:String handling in java

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 );
}
}
}


 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give a better example
wondered how you get 131
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic