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: Deficient Number Code?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Deficient Number Code?

    I'm in an introductory java class and need some desperate help on my project. What the code has to do is have the user enter an integer and then it gives the amount of deficient numbers up to that integer. He gave us a similar code shown below that uses prime numbers instead. I don't even know where to start with this or what to change so any help at all would be greatly appreciated. The code he gave us was this:


    import java.util.Scanner;
    public class Prime
    {
    public static void main (String[] args)
    {
    Scanner s = new Scanner(System.in);
    int n, f, fcount, p, a;
    p = 0;
    System.out.print("Enter an integer:");
    a = s.nextInt();

    for (n = 1; n<=a; n++)
    {
    System.out.print(n + "\t");
    fcount = 0;
    for (f = 1; f <= n/2; f++)
    if (n % f == 0)
    {
    System.out.print(f + " ");
    fcount++;
    }
    if (fcount == 1)
    p++;
    System.out.println();
    }
    System.out.println("Number of primes = " + p);
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Deficient Number Code?

    Please don't post multiple copies of the same question. I deleted your duplicate thread. Also, please use the highlight tags when posting code.

    Recommended reading: http://www.javaprogrammingforums.com...e-posting.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Deficient Number Code?

    What is a deficient number?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Deficient Number Code?

    Quote Originally Posted by Norm View Post
    What is a deficient number?
    Seven. Never liked it much. Also, thirteen is pretty deficient as well.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Deficient Number Code?

    To each his own.

Similar Threads

  1. Prime Number Code Help!
    By aandcmedia in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 7th, 2012, 12:07 AM
  2. Do Loop, Reversing a Number Example, Incorrect Code in Book?
    By djl1990 in forum Loops & Control Statements
    Replies: 3
    Last Post: October 24th, 2011, 07:01 AM
  3. Help with code that prints number of evens, odds, and 0's
    By trogan234 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 2nd, 2011, 06:50 PM
  4. [SOLVED] Help with code, Says number is NaN and i cant format it
    By NewGuy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 4th, 2010, 08:28 PM

Tags for this Thread