File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java program" Watch "java program" New topic
Author

java program

Shreegowri Bhojanna
Greenhorn

Joined: Feb 13, 2014
Posts: 10
Hi,
I need a program that gives largest distance of occurrence of a given character in a given string.
For example, Given string "my name is samitha" and given a character "a" pgm should output 7.
I tried but got error.

Thanks in advance.
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 1173
    
  65

This isn't really a job discussion so I moved it from that forum over to Java in General.

Shreegowri Bhojanna wrote:I tried but got error

Tried what?

You're not going to get a ready made answer here but if you show us what you've tried so far and explain what the current problem is that you are facing then you are more likely to get some constructive help.


Tim Driven Development
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

An example is great, but it doesn't really make a spec. Why 7 and not 13?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
I would expect the String.indexOf and lastIndexOf methods to come in handy.

Although if 7 is a possible solution, then 12 would be more likely to be another one than 13. It all depends on how "distance" is defined. So we really need that spec, like Fred said.


Ping & DNS - my free Android networking tools app
Shreegowri Bhojanna
Greenhorn

Joined: Feb 13, 2014
Posts: 10
fred rosenberger wrote:An example is great, but it doesn't really make a spec. Why 7 and not 13?



Hi, I have the same doubt but it was the question asked for me in one of the online java exam.
And it was like i should get the same answer they specified.
Paul Murray-Cbr
Greenhorn

Joined: Aug 24, 2014
Posts: 12

I think he must mean 'the greatest distance between any two consecutive occurrences.

One way to deal with these sorts of problems is to ask "how would I go about doing this if I did not have a computer?" Then get your computer to do it that way.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8196
    
  23

Shreegowri Bhojanna wrote:Hi, I have the same doubt but it was the question asked for me in one of the online java exam.
And it was like i should get the same answer they specified.

What online Java exam?

I'm afraid we aren't mind-readers Shreegowri, so you need to supply information. Otherwise, we're just shooting in the dark.

However, I'd definitely follow Paul's advice: Forget all about Java, and work out how YOU would do it.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

You said "I tried but got an error". That doesn't tell us much. There are something like one million ways you could "try and get an error". If we start guessing - i.e. saying "did you do this? how about this? Well, maybe this?", it will take us a LONG time to find the solution to your problem.

so, please post your code. Tell us EXACTLY what happens when you compile and/or run it. Your job is to provide the details and make it as easy as possible for us to help you. I would suggest you read some of our How To Ask Questions FAQ first.
Shreegowri Bhojanna
Greenhorn

Joined: Feb 13, 2014
Posts: 10
k k, I got it.I found out the error, while passing parameter i used String instance instead of BufferedString.
Anyhow thank you for all suggestions next time while posting first i will post my code.
And sorry to all of you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
What's a BufferedString?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java program