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

Thread: Help me to fix the error in my programming.

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me to fix the error in my programming.

    Hi,

    I have complied and run the following program.

    I countMax part of the program is not printing. Can some one help me to fix it.

    public class PrintDivisor {
    public static void main(String[] args) {

    int N=1;
    int count=0;
    int countMax =0;

    do{
    System.out.print(N+" : ");
    for(int divisor=1; divisor<=N; divisor++){
    if(N%divisor == 0){
    count++;
    System.out.print(divisor+",");
    }
    }
    System.out.println();
    System.out.printf("The integer %d has %d divisors", N, count);
    System.out.println();
    if(countMax <= count){
    countMax=count;
    System.out.printf("The integer %d has max divisors %d.", N, countMax);
    }
    count=0;
    N++;
    }while(N<=10000);
    }
    }

  2. #2
    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: Help me to fix the error in my programming.

    countMax part of the program is not printing
    Is there an if statement that controls that printing? Is the condition in the if statement ever true to allow printing?
    Add a print statement just before the if statement that prints the values in the if statement so you can see what the computer sees when it executes the if statement.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help me to fix the error in my programming.

    Quote Originally Posted by Norm View Post
    Is there an if statement that controls that printing? Is the condition in the if statement ever true to allow printing?
    Add a print statement just before the if statement that prints the values in the if statement so you can see what the computer sees when it executes the if statement.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    Hi,
    Thank you. Introduced a new variable maxInt and took printing out of if statement. It works well.

Similar Threads

  1. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 25th, 2013, 01:36 AM
  2. Cant fix this error... Help!
    By Hypermegazord in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 1st, 2012, 01:06 PM
  3. Blackjack programming error (programmer is new to programming)
    By JSingh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2012, 09:13 PM
  4. Replies: 1
    Last Post: August 5th, 2012, 09:28 PM
  5. Simply error; can't quite fix it.
    By JRabbit in forum Android Development
    Replies: 1
    Last Post: March 19th, 2012, 06:46 PM