Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: [METHOD] How: Count how many prime numbers there is between two numbers!

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [METHOD] How: Count how many prime numbers there is between two numbers!

    Hello!

    I'm currently making a new program that will count how many prime numbers there is between two numbers (let's say 1 - 50).

    I just wonder how do I make this method? Or do I need a for loop also?

    This is how far I have become atm.. Please tell me if I have made something wrong.

    OBS! There will also be a class with a main method which is not created yet.

    import java.util.Scanner;
     
    class Prime
    {
    	private int number1;
    	private int number2;
    	private int[] primenumber1;
     
    	public Prime(int n1, int n2, int[] p1 ); {
    		System.out.print("Write in the first number:");
    		int under = s.nextInt();
    		System.out.print("Write in the second number:");
    		int over = s.nextInt();
     
    		this.number1 = n1;
    		this.number2 = n2;
    		this.primenumber1 = p1;
    	}
     
    	public int getNumber1()
    	{
    		return this.Number1;
    	}
     
    	public void setNumber1()
    	{
    		this.number1 = n1;
    	}
     
    	public int getNumber2()
    	{
    		return this.Number2;
    	}
     
    	public void setNumber2()
    	{
    		this.number2 = n2;
    	}
     
    	public int getPrime()
    	{
    		return this.primenumber1;
    	}
     
     
     
    }


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Location
    Delhi
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [METHOD] How: Count how many prime numbers there is between two numbers!

    /* If getting problem in understanding, let me know at my id saurabhmittal1987@gmail.com
    Now you can add anything like menu to your code to use some unused methods like setNumber1 etc et
    */

    Edited by moderator
    Last edited by copeg; October 16th, 2011 at 03:55 PM.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: [METHOD] How: Count how many prime numbers there is between two numbers!

    Saurabh Mittal, please read the forum rules and the following link:

    The Problems with Spoonfeeding

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Re: [METHOD] How: Count how many prime numbers there is between two numbers!

    hi dude this code will help you .. i just did it
    ...edited by moderator....
    Last edited by copeg; October 18th, 2011 at 02:29 PM.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: [METHOD] How: Count how many prime numbers there is between two numbers!

    Quote Originally Posted by bojwess View Post
    hi dude this code will help you .. i just did it
    ...edited by moderator....
    Evidently new contributors to the forums don't read the forum rules, or previous posts on the subject. bojwess, while we appreciate your participation I point you to the link I provided in my post above, and the forum rules post at the top of every forum. Your post has been edited

Similar Threads

  1. Prime Factorization Method: Won't reproduce all Factors every time
    By Staticity in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 30th, 2011, 05:16 AM
  2. trying to generate prime numbers
    By yingyang69 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 28th, 2011, 12:21 PM
  3. Display prime numbers from 100 to 200 in Java
    By c.P.u1 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 25th, 2011, 03:14 PM
  4. prime numbers
    By tdz013 in forum Java Theory & Questions
    Replies: 4
    Last Post: January 13th, 2011, 11:24 AM
  5. Generate prime numbers within fiboncacci series?
    By Manish87 in forum Algorithms & Recursion
    Replies: 5
    Last Post: August 7th, 2010, 12:24 PM