How to find factors of number?

I have a prime number program set up that finds prime numbers and to find two prime numbers beyond the number inputed. I also want to find the factors of the number inputed. I am brain freezed on finding the factors. For example I want to display 20 = 2 x 2 x 5, and for prime numbers I want to display 7 = 7. The factors will be displayed in label.
I already have the first factor, but how do you continue to add factors to the string, that is going to be put into the label? I think it is a for loop in a for loop but not sure how to work it out??????
here is my factor method
private void factor(long value)   //bring in number from user
          long firstVal;
          String output = value + " = ";
               for (long a = 2; a < 12; a += 1)
                    if (value % a == 0)
                         firstVal = value / a;
                         output = output + a + "x";
     }//factor-thanks

Well that was to illustrate the point so that the person asking question can take correct direction.
But you don't want to use your brain at all right.
Then here is the code
import java.math.*;
import java.util.*;
public class DirectSearchFactorization {
  private long max = 0;
  private Vector trialDivisors = null;
  private long nDivisions = 0;
  // Constructor
  public DirectSearchFactorization (long max) {
    this.max = max;
    // The trial divisors include all primes <= sqrt (n).
    // The trial divisors must also contain at least one
    // value such that d(k) >= sqrt (n).
    int sqrtn = (int) Math.ceil (Math.sqrt (max));
    trialDivisors = SieveOfEratosthenes.getPrimes (sqrtn);
    trialDivisors.addElement (new Long (sqrtn));
  public long getNumDivisions () {
    return nDivisions;
  // Get prime factors
  public Vector getPrimeFactors (long n) {
    if (n > max) {
      String s = n + " > " + max;
      throw new IllegalArgumentException (s);
    Vector factors = new Vector ();
    nDivisions = 0;
    // Step 1
    int k = 0;
    long divisor;
    Long divisorObj;
    long quotient;
    long remainder;
    // Step 2
    while (n > 1) {
      // Step 3
      divisorObj = (Long) trialDivisors.elementAt (k);
      divisor = divisorObj.longValue ();
      quotient = (long) Math.floor (n / divisor);
      remainder = n % divisor;
      nDivisions++;
      // Step 4
      if (remainder == 0) {
        // Step 5
        factors.addElement (new Long (divisor));
        n = quotient;
      else {
        // Step 6
        if (quotient > divisor) {
          k++;
        else {
          // Step 7
          factors.addElement (new Long (n));
          break;
    return factors;
import java.util.*;
public abstract class SieveOfEratosthenes {
  public static Vector getPrimes (int upTo) {
    int size = upTo + 1;
    boolean [] flags = new boolean[size];
    Vector primes = new Vector ();
    double limit = Math.sqrt (size);
    // Set flags
    for (int i = 2; i < size; i++) {
      flags[i] = true;
    // Cross out multiples of 2
    int j = 2;
    for (int i = j + j; i < size; i = i + j) {
      flags[i] = false;
    // Cross out multiples of odd numbers
    for (j = 3; j <= limit; j = j + 2) {
      if (flags[j]) {
        for (int i = j + j; i < size; i = i + j) {
          flags[i] = false;
    // Build list of primes from what is left
    for (int i = 2; i < size; i++) {
      if (flags) {
primes.addElement (new Long (i));
return primes;
User Interface
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
// The applet tests the DirectSearchFactorization class
public class FactorizationApplet extends Applet {
private Button factorButton = null;
private Label numberLabel = null;
private TextField numberTextField = null;
private Label numDivisionsLabel = null;
private TextField numDivisionsTextField = null;
private Label factorsLabel = null;
private TextField factorsTextField = null;
private DirectSearchFactorization dsf = null;
private static final long MAX = 500000;
// Override Applet methods
public void init () {
Panel panel = new Panel ();
panel.setLayout (new GridLayout (3, 2));
numberLabel = new Label ("Number to Factor <= " + Long.toString (MAX));
panel.add (numberLabel);
numberTextField = new TextField ("387921", 25);
panel.add (numberTextField);
factorsLabel = new Label ("Prime Factors");
panel.add (factorsLabel);
factorsTextField = new TextField ("", 25);
factorsTextField.setEditable (false);
panel.add (factorsTextField);
numDivisionsLabel = new Label ("Number of Divisions");
panel.add (numDivisionsLabel);
numDivisionsTextField = new TextField ("", 25);
numDivisionsTextField.setEditable (false);
panel.add (numDivisionsTextField);
add (panel);
factorButton = new Button ("Factor");
add (factorButton);
dsf = new DirectSearchFactorization (MAX);
public void paint (Graphics g) {
public boolean action (Event e, Object arg) {
if (e.target == factorButton) {
factor ();
repaint ();
return true;
else {
return false;
private void factor () {
long n = 0;
factorsTextField.setText ("");
try {
n = Long.parseLong (numberTextField.getText ());
if (n <= MAX) {
Vector factors = dsf.getPrimeFactors (n);
factorsTextField.setText (factors.toString ());
numDivisionsTextField.setText (Long.toString (dsf.getNumDivisions ()));
} catch (Exception e) {
System.out.println (e.toString ());
// Run as application
public static void main (String[] args) {
// Create frame to house the applet
Frame frame = new Frame ("Factorization into Primes");
// Create an instance of the applet
FactorizationApplet app = new FactorizationApplet ();
// Add it to the center of the frame
frame.add (app, BorderLayout.CENTER);
frame.setSize (450, 150);
// Listen for window closing event
frame.addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent e) {
System.exit (0);
// Call the applet methods
app.init ();
app.start ();
// Set the frame visible
frame.setVisible (true);

Similar Messages

  • How to find out spool number from a jobname.

    Hi,
    If I know the jobname and jobcount how to find the spool number of it. Jobname and Jobcount are in table TBTCO and spool number is in TSP01. Is there any link between these tables.
    Your help will be appreciated.
    Thanks & Regards,
    Soumya.

    Hi,
    Check the below link
    [Re:Spool request;
    Regards,
    Surinder

  • How to find out the Number range object for Incident number

    How to find out the Number range object for Incident number ?
    CCIHT_IAL-IALID
    regards,
    lavanya

    HI, an example.
    data: vl_num type i,
          vl_char(6) type c,
          vl_qty type INRI-QUANTITY,
          vl_rc type INRI-RETURNCODE.
    CALL FUNCTION 'NUMBER_GET_NEXT'
      EXPORTING
        NR_RANGE_NR                   = '01'
        OBJECT                        = 'ZRG0000001'
       QUANTITY                       = '1'
      SUBOBJECT                     = ' '
      TOYEAR                        = '0000'
      IGNORE_BUFFER                 = ' '
    IMPORTING
       NUMBER                        = vl_num
       QUANTITY                      = vl_qty
       RETURNCODE                    = vl_rc
    EXCEPTIONS
       INTERVAL_NOT_FOUND            = 1
       NUMBER_RANGE_NOT_INTERN       = 2
       OBJECT_NOT_FOUND              = 3
       QUANTITY_IS_0                 = 4
       QUANTITY_IS_NOT_1             = 5
       INTERVAL_OVERFLOW             = 6
       BUFFER_OVERFLOW               = 7
       OTHERS                        = 8
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    vl_char = vl_num.
    write vl_char.
    Regard

  • How to find out the number of songs in my iTunes 11 library

    How to find out the number of songs in my iTunes 11 library

    Welcome to the Apple Support Communities
    To see the number of songs, go to View menu > Show Status Bar, so the number of songs you have will appear at the bottom of the iTunes window

  • How to find out asset number in SAP

    Hi,
    Please let me know how to find out asset number based on the depreciation document number.
    Regards,
    Bhaskar Suruvu

    In the FI document header text / line item text you found back the asset document number like:
    AFB01200900101-0000000001
    In the table ANLP you can found back the document number -0000000001
    On this way you can make the link

  • How to find ThinkPad serial number if label is worn?

    QuestionI'm having some trouble with my T500 ThinkPad and want to contact service, but am not sure how I can find out the machine type and serial number to provide to support when I call because the sticker on the bottom of the laptop is faded so I don't know what the S/N is. I do have one number though: [serial removed] was what I copied down from it before it became faded. I dont know what to do now, so if you have any ideas, that'd be great.
    Answer 
    Generally the label with type and serial information is found on the bottom of laptops and tablets and on the rear of desktop systems and on the back or along the edge of displays.   As noted by the question asked above, in some cases, the label may become worn.  To reduce / avoid this, the type / serial label was relocated to the battery compartment on some systems with removable batteries, along with the Win 7 COA.  As Win 8 does not have a COA lable, and print technologies for labels have improved, most current systems have the label on the bottom.
    Some tablets may have the type and serial information label on the inside of memory door / SD card slot covers as was the case with the ThinkPad tablet type 1838/1839.
    Here is a link to an article on the support site with examples of label locations for different model Lenovo systems.   If the system will not power up at all, finding the physical label is the best course of action when contacting service.
    If the label is missing and the system will power up, there are several ways to easily find this information as it is written into the BIOS on the system board.
    1) Command Prompt
    Run an elevated command prompt, Enter the command "wmic bios get serialnumber" (without the quotations).
    2) BIOS
    Boot to BIOS (press F1 on startup) and the model type and serial number will be listed.
    3) Diagnostics - Lenovo Solution Center (LSC) or the prior Lenovo ThinkVantage toolbox.

    wmic bios get serialnumber  does not work !!!!all your pages about how to find a serial number are disfunctuional !!! What a bed service

  • How to find my serial number in downloaded logic pro X

    how to find my serial number in downloaded logic pro X

    There is no serial number for Logic Pro X

  • How to find ipod serial number on itunes?

    i need to find out what my serial number was for a stolen ipod. how can i do this on itunes?

    See:
    iOS: How to find the serial number, IMEI, MEID, CDN, and ICCID number

  • I have no idea how to find my serial number to launch Lightroom. I have the student teacher edition and I'm using a mac

    I have no idea how to find my serial number to launch Lightroom. I have the student teacher edition and I'm using a mac.

    How did you purchase Lightroom? Download? Package?
    Have you followed the instructions to verify that you qualify for academic discount?

  • How to find Error Reference Number Additional details in HFM

    <font color="Blue">
    Hi All
    How to find Error Reference Number additional details in HFM ?
    Example:
    Error Reference Number:{01977FBD-DB42-4655-99B5-4ABF38D3E082}
    Where to Find above id additional details??
    I mean HSVErrorLogViewer ? OR RegistrySettings ? OR Dcomcnfg ? OR any other way to find the detailed information?
    Any ideas? Appreciate your help in advance.
    Regards
    Taruni
    </font>

    Hi,
    try menu - EDIT - LUW debug
    and see if you can get the idoc number in this way
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

  • How to find out cellular number on ipad

    I have forgotten my cell number that m using for 3G on my ipad 2. Please let me know how to find out cell number on ipad 2

    Make sure that your Cellular Data button is turned on:
    CELLULAR DATA>CELLULAR DATA = ON
    Then the number should show up where Diavonex indicated above

  • How to find Outbound Idoc number from inbound Idoc number.

    Hi,
    I have one inbound Idoc in my system, then
    How to find the  idoc number from the system which sends that idoc(Outbound Idoc number).

    Hello
    You can use fm SREL_GET_NEXT_NEIGHBORS for this purpose.
    Scenario: An EDI purchase order is received by SAP-XI and forwarded as Inbound ORDERS IDoc to R/3. SAP-XI generates an (outbound) IDoc number which differs from the (inbound) ORDERS05 IDoc in the R/3 system.
    Calling fm SREL_GET_NEXT_NEIGHBORS with the following parameters:
    OBJECT-OBJKEY = <IDoc number, 16-digits>
    OBJECT-OBJTYPE = 'IDOC'
    MAX_HOPS = '99'            " <<< get all links
    I get the following result:
    0000000000133906                                   IDOC       CUSTOMER   OUTIDOC
    0000000000407402                                   IDOC                  INIDOC
    000000370383                                       BUS2012    CUSTOMER   OUTBELEG
    0010057944                                         BUS2032               INBELEG
    Outbound IDoc number
    Inbound IDoc number (ORDERS05)
    PO number
    Sales order (created from inbound ORDERS IDoc)
    Regards
      Uwe

  • Someone stole my 4th gen. Ipod touch and i don't know how to find the serial number... Can you track it?

    I dont know how to find the serial number and someone stole my i pod can someone track it?

    You can easily get the serial number.  Having it will not help you track it.
    iPod: How to find the serial number
    If you activated find my ipod on the ipod BEFORE it went missng, then you may be able to track it.
    Otherwise, you cannot track it.

  • HT2452 How to find the serial number of your Apple hardware product

    How to find the serial number of your Apple hardware product

    This works for any Mac provided that the logic board has not been replaced.
    I recently had the logic board replaced in my iMac. After the tech left (on site repair thanks to Applecare), I went to about the Mac and found jibberish numbers. I called Apple and the AASP and found that he had forgotten to register the serial number. So he came back and, with a special tool (as he called it - looked a little like a USB stick) he contacted Apple and then entered my original serial number as I read it to him.
    So, I assume they changed the process since I still have the same serial number as before.

  • TS1702 how to find the serial number, after purchase Pages online?

    how to find the serial number, after purchase Pages online?

    If you downloaded the standalone trial version of Lightroom, it will be necessary for you to uninstall that version. Then you will be able to install Lightroom through the creative cloud application manager. After you install Lightroom that way, just double-click on the catalog that you have already started.

Maybe you are looking for

  • Apple TV won't connect to iTunes and does not show up in my devices list in iTunes.

    My older model Apple TV won't connect to iTunes and does not show up in my devices list in iTunes.  I have two Apple TVs in my house and I can't imagine that this is part of the problem but I mention it just in case.  My other Apple TV is brand new a

  • Where can i learn about Boot Camp

    to all i would like to learn about boot camp and the risks of puttiong windows on my mac. some things i just need on windows. where can i read about it before i start to post dumb questions about virus software and the risk of virus, as i'm sure its

  • Font antialiasing in Word 2007 with Wine

    Is there any way to get antialiasing in Word 2007 with Wine? Also I'm having some problems with bullets, they don't show up right. Maybe I'm missing a package for Wine or something? Thanks

  • Cross Web Applications Communication in Portal

    does anybody knows how multiple web apps communicate in Portal? How are data exchanged? is there a global session or something like this? thanks and best regards carlo

  • How to create a login certificate for BI launchpad?

    It is possible to create a security certificate (to store user name and password) and with it to be able to login to BI 4.1 launchpad without completing info at every session? just to confirm certificate (similar to SAP passport). I need a solution t