Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

finding the occurrence of two strings  RSS feed

 
bryan aviles
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im doing some work on bluej so far i created this code and edited it to get me the number of occurrences of .com now.. i have a question that says
print the number of links that end with “.com” or “.com/” does anyone know how to find double occurences of .com and .com/



~ da noob code ...

output .com = 339


 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double occurrences?

I don't quite understand what you're getting at here.

What sort of input are you running this on?
Does it actually have 339 instances of .com in it?

What about this url: www.computer.net ?
 
bryan aviles
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes they are 339 instances of .com,
a question im struggling on is How many URLs on this website end with either ".com" or ".com/"?
.... i dont quite know how to create a code to solve this problem..




 
Paul Clapham
Sheriff
Posts: 22530
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what all of that code is for, but if you want to know whether a String ends with a particular character sequence then the endsWith() method is what you should be using. You aren't using that method.

I see some code which looks like it's trying to extract URLs, but it's a bit dodgy. Maybe it'll work for the website which you're working with right now, though. But then it looks like it's trying to count the number of times a URL contains ".com". It would be much easier to just use the endsWith() method.

I also don't know what you mean by "double occurrence" -- you're really going to have to explain what that means if you want us to understand what your problem is.
 
bryan aviles
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind about double occurrence lol i just need to solve this question

How many URLs on this website end with either ".com" or ".com/"? oh! and its for some course online, im just trying to learn how to write code in java

and i need to make a code to find total number of .com .com/ but i have no idea how to... thanks for the reply paul!


 
Paul Clapham
Sheriff
Posts: 22530
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you have about 80% of the code already written, or so it seems to me. So you surely have some idea, or you wouldn't have got that far. Or is that code something you got from somewhere else, and you're trying to fix it up?
 
bryan aviles
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got a lot of the code from lecture videos on an online course and some code from the internet to solve other question . i do have an idea on how to do it... but it's so confusing well at least for me , im considering on buying a book on problem solving in java any recommended books you have in mind?
 
Paul Clapham
Sheriff
Posts: 22530
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way I looked at the source of that web page you're accessing, and I find 11 instances of some quoted string ending in ".com" and 8 instances of some quoted string ending in ".com/". Not all of those are in URLs, either. So it may be that you are misinterpreting or misquoting the requirements.
 
bryan aviles
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many URLs on this website end with either ".com" or ".com/"?

Answer i put is 411 xD

Incorrect Response

its like the last question i need to get right to move on with more lecture videos haha
ms1.PNG
[Thumbnail for ms1.PNG]
this is the output i got ..
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bryan aviles wrote:How many URLs on this website end with either ".com" or ".com/"?

It seems unlikely to me that a URL will end with ".com/". It might contain it though.

So it seems to me that you have two checks to make:
  endsWith(".com")   and
  matches(".*[.]com/.*")
although I don't know if you're allowed to use regular expressions or not.

HIH

Winston
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bryan aviles wrote:its like the last question i need to get right to move on with more lecture videos..
You don't at the moment, at most you'd probably remind yourself language mechanics there.

It seems that you still don't understand well your actual exercise, or not expressing yourself clear, so we don't understand.
Try not to improvise with instructions you give us, but rather copy and paste it here. We have seen last week few students who misinterpreted their instructions, so attempts to write the code were a bit waste of time, more importantly - it were wrong.

1. Post exact requirements
2. Give us some sample textual data where those URL's are listed (not picture, textual)

 
bryan aviles
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i solved my problem i just debugged the code and understood what it was doing and created an algorithm to find what i want.lol now it's time for me to find a book on problem solving in java thanks for the concern following people above ^^^^ i don't even know how this websites works. How do you tag someone?...
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bryan aviles wrote:i don't even know how this websites works. How do you tag someone?...

You don't generally - you tag posts that are useful - which you can do by pressing the "thumbs-up" button.

There are two, so make sure it's the one with '+1' on it if you want to "reward" someone .

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!