count how many times a prime is dividing a number










0














I'm a beginner, my code finds all the primes that divide a given number but I want it to also print how many times the prime divides.
this is my code:



public static void main()
Scanner myScanner = new Scanner (System.in) ;
int n = myScanner.nextInt();
int prime = 2 ;
int count = 0 ;
while ( prime <= n )
if ( n%prime == 0 )
n = n/prime ;
System.out.println(prime + " " +count);

if ( n%prime !=0 )
prime = prime + 1;





Hope you'll understand me, thanks!!










share|improve this question



















  • 2




    you are not increasing your counter, add "count++;" before the print.
    – dorony
    Nov 10 at 21:54















0














I'm a beginner, my code finds all the primes that divide a given number but I want it to also print how many times the prime divides.
this is my code:



public static void main()
Scanner myScanner = new Scanner (System.in) ;
int n = myScanner.nextInt();
int prime = 2 ;
int count = 0 ;
while ( prime <= n )
if ( n%prime == 0 )
n = n/prime ;
System.out.println(prime + " " +count);

if ( n%prime !=0 )
prime = prime + 1;





Hope you'll understand me, thanks!!










share|improve this question



















  • 2




    you are not increasing your counter, add "count++;" before the print.
    – dorony
    Nov 10 at 21:54













0












0








0







I'm a beginner, my code finds all the primes that divide a given number but I want it to also print how many times the prime divides.
this is my code:



public static void main()
Scanner myScanner = new Scanner (System.in) ;
int n = myScanner.nextInt();
int prime = 2 ;
int count = 0 ;
while ( prime <= n )
if ( n%prime == 0 )
n = n/prime ;
System.out.println(prime + " " +count);

if ( n%prime !=0 )
prime = prime + 1;





Hope you'll understand me, thanks!!










share|improve this question















I'm a beginner, my code finds all the primes that divide a given number but I want it to also print how many times the prime divides.
this is my code:



public static void main()
Scanner myScanner = new Scanner (System.in) ;
int n = myScanner.nextInt();
int prime = 2 ;
int count = 0 ;
while ( prime <= n )
if ( n%prime == 0 )
n = n/prime ;
System.out.println(prime + " " +count);

if ( n%prime !=0 )
prime = prime + 1;





Hope you'll understand me, thanks!!







java primes divide






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 21:48









Stav Alfi

3,91774079




3,91774079










asked Nov 10 at 21:44









Sapirush Kalifa

6




6







  • 2




    you are not increasing your counter, add "count++;" before the print.
    – dorony
    Nov 10 at 21:54












  • 2




    you are not increasing your counter, add "count++;" before the print.
    – dorony
    Nov 10 at 21:54







2




2




you are not increasing your counter, add "count++;" before the print.
– dorony
Nov 10 at 21:54




you are not increasing your counter, add "count++;" before the print.
– dorony
Nov 10 at 21:54












2 Answers
2






active

oldest

votes


















0














You forgot to increase the counter:



System.out.println(prime + " " +(++count));





share|improve this answer




























    0














    You need to increase the counter for every division that has a remainder 0

    and you must exit the loop once the remainder is not 0:



    public static void main(String args) 
    Scanner myScanner = new Scanner (System.in) ;
    int n = myScanner.nextInt();
    int prime = 2;
    int count = 0;

    while ( prime <= n )
    if ( n % prime == 0 )
    n /= prime;
    count++;
    else
    break;


    System.out.println(prime + " " +count);






    share|improve this answer






















    • it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
      – Sapirush Kalifa
      Nov 10 at 22:27











    • No it print 2 2. Copy the code and run it again
      – forpas
      Nov 10 at 22:28











    • @SapirushKalifa did you copy my code or something else?
      – forpas
      Nov 10 at 22:49










    • tried, didn't work
      – Sapirush Kalifa
      Nov 11 at 9:16










    • What didn't work? Don't you want to print 2 2 when you set number to 100?
      – forpas
      Nov 11 at 9:17










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243710%2fcount-how-many-times-a-prime-is-dividing-a-number%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You forgot to increase the counter:



    System.out.println(prime + " " +(++count));





    share|improve this answer

























      0














      You forgot to increase the counter:



      System.out.println(prime + " " +(++count));





      share|improve this answer























        0












        0








        0






        You forgot to increase the counter:



        System.out.println(prime + " " +(++count));





        share|improve this answer












        You forgot to increase the counter:



        System.out.println(prime + " " +(++count));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 21:58









        HaroldSer

        1,3162615




        1,3162615























            0














            You need to increase the counter for every division that has a remainder 0

            and you must exit the loop once the remainder is not 0:



            public static void main(String args) 
            Scanner myScanner = new Scanner (System.in) ;
            int n = myScanner.nextInt();
            int prime = 2;
            int count = 0;

            while ( prime <= n )
            if ( n % prime == 0 )
            n /= prime;
            count++;
            else
            break;


            System.out.println(prime + " " +count);






            share|improve this answer






















            • it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
              – Sapirush Kalifa
              Nov 10 at 22:27











            • No it print 2 2. Copy the code and run it again
              – forpas
              Nov 10 at 22:28











            • @SapirushKalifa did you copy my code or something else?
              – forpas
              Nov 10 at 22:49










            • tried, didn't work
              – Sapirush Kalifa
              Nov 11 at 9:16










            • What didn't work? Don't you want to print 2 2 when you set number to 100?
              – forpas
              Nov 11 at 9:17















            0














            You need to increase the counter for every division that has a remainder 0

            and you must exit the loop once the remainder is not 0:



            public static void main(String args) 
            Scanner myScanner = new Scanner (System.in) ;
            int n = myScanner.nextInt();
            int prime = 2;
            int count = 0;

            while ( prime <= n )
            if ( n % prime == 0 )
            n /= prime;
            count++;
            else
            break;


            System.out.println(prime + " " +count);






            share|improve this answer






















            • it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
              – Sapirush Kalifa
              Nov 10 at 22:27











            • No it print 2 2. Copy the code and run it again
              – forpas
              Nov 10 at 22:28











            • @SapirushKalifa did you copy my code or something else?
              – forpas
              Nov 10 at 22:49










            • tried, didn't work
              – Sapirush Kalifa
              Nov 11 at 9:16










            • What didn't work? Don't you want to print 2 2 when you set number to 100?
              – forpas
              Nov 11 at 9:17













            0












            0








            0






            You need to increase the counter for every division that has a remainder 0

            and you must exit the loop once the remainder is not 0:



            public static void main(String args) 
            Scanner myScanner = new Scanner (System.in) ;
            int n = myScanner.nextInt();
            int prime = 2;
            int count = 0;

            while ( prime <= n )
            if ( n % prime == 0 )
            n /= prime;
            count++;
            else
            break;


            System.out.println(prime + " " +count);






            share|improve this answer














            You need to increase the counter for every division that has a remainder 0

            and you must exit the loop once the remainder is not 0:



            public static void main(String args) 
            Scanner myScanner = new Scanner (System.in) ;
            int n = myScanner.nextInt();
            int prime = 2;
            int count = 0;

            while ( prime <= n )
            if ( n % prime == 0 )
            n /= prime;
            count++;
            else
            break;


            System.out.println(prime + " " +count);







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 22:15

























            answered Nov 10 at 22:09









            forpas

            7,9961419




            7,9961419











            • it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
              – Sapirush Kalifa
              Nov 10 at 22:27











            • No it print 2 2. Copy the code and run it again
              – forpas
              Nov 10 at 22:28











            • @SapirushKalifa did you copy my code or something else?
              – forpas
              Nov 10 at 22:49










            • tried, didn't work
              – Sapirush Kalifa
              Nov 11 at 9:16










            • What didn't work? Don't you want to print 2 2 when you set number to 100?
              – forpas
              Nov 11 at 9:17
















            • it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
              – Sapirush Kalifa
              Nov 10 at 22:27











            • No it print 2 2. Copy the code and run it again
              – forpas
              Nov 10 at 22:28











            • @SapirushKalifa did you copy my code or something else?
              – forpas
              Nov 10 at 22:49










            • tried, didn't work
              – Sapirush Kalifa
              Nov 11 at 9:16










            • What didn't work? Don't you want to print 2 2 when you set number to 100?
              – forpas
              Nov 11 at 9:17















            it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
            – Sapirush Kalifa
            Nov 10 at 22:27





            it's not exectly what I want, lets say n=100, it prints: 2 1 2 2 5 3 5 5 I want it to print: 2 2 5 2
            – Sapirush Kalifa
            Nov 10 at 22:27













            No it print 2 2. Copy the code and run it again
            – forpas
            Nov 10 at 22:28





            No it print 2 2. Copy the code and run it again
            – forpas
            Nov 10 at 22:28













            @SapirushKalifa did you copy my code or something else?
            – forpas
            Nov 10 at 22:49




            @SapirushKalifa did you copy my code or something else?
            – forpas
            Nov 10 at 22:49












            tried, didn't work
            – Sapirush Kalifa
            Nov 11 at 9:16




            tried, didn't work
            – Sapirush Kalifa
            Nov 11 at 9:16












            What didn't work? Don't you want to print 2 2 when you set number to 100?
            – forpas
            Nov 11 at 9:17




            What didn't work? Don't you want to print 2 2 when you set number to 100?
            – forpas
            Nov 11 at 9:17

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid …


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid …


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243710%2fcount-how-many-times-a-prime-is-dividing-a-number%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線