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 7 of 7

Thread: new to programming

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

    Default new to programming

    I'm new with programming so I'd appreciate if you guys could help me out with this one.

    I have to write a program consisting this:

    Write a static method called countDivisors that figures out how many positive integers are divisors of the supplied int parameter. It should take in a single int parameter and return an int, indicating how many divisors there are (you can assume that the parameter supplied by the caller will always be a positive integer). For example, countDivisors(10) should result in 4, whereas countDivisors(9) should result in 3.

    Since a prime number is (by definition) a positive int that has exactly 2 divisors, it should now be a straightforward matter to determine whether or not an int is a prime number. Using your countDivisors method, write a program that takes an int from the user, determines whether or not it is a prime number, and reports the number of divisors:


    I don't have a clue what to do, any help would be appreciated. thank you


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: new to programming

    Well what have you done so far? Take things step-by-step and break down what you need to do. It's a good idea to start by writing down what the program is required to do without any coding first. The first part is asking to create a static method with an int parameter that finds out how many divisors a positive integer has. The second part asks to determine whether it is prime. Since it tells you what to do, try to think about how to go about doing this.

    For example,
    10 has 4 divisors: 1, 2, 5, 10
    9 has 3 divisors: 1, 3, 9
    8 has 4 divisors: 1, 2, 4, 8
    7 has 2 divisors: 1, 7 <----- prime, because it has ONLY 2 divisors
    etc...

    Again, think about what you could use to determine this before actually coding anything. Once you do and have some code but are still stuck, then please post what you're still having trouble on.

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

    Default Re: new to programming

    alright, what I'm confused on though is how to write a code that determines how many divisors a number has

  4. #4
    Junior Member
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: new to programming

    There is a math function called modulus that will do the work for you.

    The Remainder or Modulus Operator in Java

  5. #5
    Junior Member Rex the king's Avatar
    Join Date
    Oct 2011
    Location
    INDIA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Re: new to programming

    see using array we can achieve this .i have a concept in my mind this time
    see using mod operator, we can find out the modulus of the number and inserting that one in array side by side updating array each time .
    Hope this would hep

  6. #6
    Junior Member Rex the king's Avatar
    Join Date
    Oct 2011
    Location
    INDIA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: new to programming

    ...edited by moderator
    Last edited by copeg; October 29th, 2011 at 11:11 AM.

  7. #7
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,104
    Thanks
    169
    Thanked 780 Times in 726 Posts
    Blog Entries
    5

    Default Re: new to programming

    @Rex, please read the forum rules and the following link: The Problem with Spoon-feeding

Similar Threads

  1. New to programming
    By Cranky in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 22nd, 2011, 09:41 AM
  2. Hi everybody, im new to programming.
    By Sauliux in forum Member Introductions
    Replies: 1
    Last Post: March 5th, 2011, 11:06 AM
  3. Java programming help
    By Cool_tine in forum Java Theory & Questions
    Replies: 1
    Last Post: February 21st, 2011, 10:05 PM
  4. [SOLVED] New to Programming
    By Delacratic in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 8th, 2011, 01:45 PM
  5. New to programming
    By Milanocookies56@gmail.com in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 31st, 2010, 09:55 AM