Hello i am new to java and o have to write a program that determines the number of prime numbers less than N which is given by the user, but i have no clue where to start

I would start with the number 1, then test if it is prime, then go to 2, and so on until N. To test if it is prime, you might want to just compare dividing it to every number below it, to see if it divides evenly.

Of course, there are faster ways to do it, but I'll leave those enhancements to you.

Well, '1' isn't a prime number. '2' is the first prime number. So maybe we could write a loop that counts from '2' up to the largest number that is just less than 'N'.

Now that we have a number, let's call it 'i' (with a value between '2' and 'N-1'), that might be prime, how can we determine if it's prime or not? Well, we could loop through all the numbers between '2' and 'i-1' to determine if dividing 'i' by that number produces a remainder. The '%' operator would probably be useful.

I'll leave the "counting" part to you.

The result would not be very efficient. But it would probably work.

Often the best way to figure out how to write a computer program is to figure out how you would do it by hand. You have to know how to do something before you can hope to teach the computer how to do it.

Think about this:
A prime number has ONLY two factors and those are 1 and the number itself.
For eg:
Factors of 2 are: 1, 2
Factors of 3 are: 1, 3
Factors of 7 are: 1, 7 and so on.....
That should get you started ;)

to find the no of prime nos less than N.
you have to find all the prime nos in the range of N.
start a loop from 1 to N
and check each and every no till N whether a no is prime or not.
if so take a counter and incement it everytime when u find a prime.

Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...

Hi. Im using vb 2010. I want to dynamically add textboxes to my form by clicking on a button. I've google searched and so far this code worked:

Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click
Dim txtB1 As New TextBox
Dim i
For i = ...