# Prime numbers

• 11-22-2013, 09:23 PM
Prime numbers
print prime numbers up to a given maximum value.
Accept the maximum value as a user input.
A prime number is only divisible by 1 and itself.

Code:

```package prime; import java.util.Scanner; public class prime {         public static void main(String[] args) {                 //----------------------------------                 //User input                 //----------------------------------                 Scanner userinput = new Scanner (System.in);                 System.out.println("enter a number");                 int input = userinput.nextInt();                 //----------------------------------                 //The for/if loop                 //----------------------------------                                 for (int l=2; l<=input; l++)                 {                         for (int k=2; k<=l; k++)                         {                                 if (l==k)                                 {                                         System.out.println(l);                                 }                                 if (l%k==0)                                 {                                         break;                                 }                         }                 }         } }```
• 11-22-2013, 09:42 PM
jim829
Re: Prime numbers
Do you have a question?

Regards,
Jim
• 11-23-2013, 01:02 AM
Re: Prime numbers
Is it correct ?
• 11-23-2013, 01:13 AM
Norm
Re: Prime numbers
What happens when the code executes? Does it produce the desired results?
• 11-23-2013, 02:02 AM
Re: Prime numbers
the results are :
enter a number
10
2
3
5
7
• 11-23-2013, 02:12 AM
Norm
Re: Prime numbers
Is that the desired output?
• 11-23-2013, 02:22 AM
Re: Prime numbers
the steps are:
print prime numbers up to a given maximum value.
Accept the maximum value as a user input.
A prime number is only divisible by 1 and itself.

so im guessing its right output and coding... im not sure on the last step tho
• 11-23-2013, 03:18 AM
jim829
Re: Prime numbers
Quote: