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: Java Program Help Please

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

    Default Java Program Help Please

    Print out 5 biggest factors of a number that is entered.

    I need help writing a program that will print out the 5 biggest factors of a number that is entered.

    For example:
    Enter A Number: 100
    The 5 Biggest Factors Are: 100, 50, 25, 20, 20.

    But if the number has less than 5 factors print out those factors.
    For example:
    Enter A Number: 7
    The factors for 7 are : 1,7

    Thanks Alot..


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java Program Help Please

    What will be the first step?

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,514
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Java Program Help Please

    Left!
    No right!
    Improving the world one idiot at a time!

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Java Program Help Please

    I was thinking more practically, kind of along the lines of,

    public class BiggestFactor {
     
      // stuff gets added here
     
      public static void main(String[] args) {
         // more stuff gets added here
      }
    }

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Java Program Help Please

    les say u looking for 5 biggest factor of x. i would use a loop. and in side i would do x % x--. if the ans is 0 than u know thats a factor. so you might want to add a control if statment in side loop, which will tell you if u found a factor or not.

    this will give you all the factor stating from biggest to smallest. and if you looking for just biggest 5. than just use a counter variable which will count 5 variable. onces you count 5 than exit from loop.

Similar Threads

  1. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  2. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 10:04 AM
  3. Java program
    By sarasaleem in forum Java Theory & Questions
    Replies: 3
    Last Post: March 1st, 2012, 05:02 AM
  4. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  5. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM