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

Thread: How can I debug this code?

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

    Question How can I debug this code?

    import java.util.Scanner;

    public class AverageSix
    {
    public void getGrades()
    {
    Scanner input = new Scanner( System.in );

    System.out.println( "Please enter the number of students you wish to average" );
    int students2 = input.nextInt();

    int NumOfStudents = students2;
    int counter = 1;
    double total = 0, previousNumber = 0, newMaximum = 0, newMinimum = 0;

    while ( students2 != 0 )
    {
    System.out.println( "Please enter a grade" );
    double givenNum = input.nextDouble();
    total = total + givenNum;

    if ( counter == 1 )
    {
    previousNumber = givenNum;
    newMinimum = givenNum;
    } // end if

    if ( newMaximum < givenNum )
    newMaximum = maximum( previousNumber, givenNum );

    if ( newMinimum > givenNum )
    newMinimum = minimum( previousNumber, givenNum );

    students2--;
    counter++;
    previousNumber = givenNum;
    } // end while

    double average1 = average( total, NumOfStudents );

    System.out.printf( "The maximum: %.2f\nThe average: %.2f\nThe minimum: %.2f\n",
    newMaximum, average1, newMinimum);
    } // end method getGrades
    } // end class AverageSix

    public double average( double x, y );
    {
    return x / y;
    } // end method average

    public double maximum( double x, double y )
    {
    Math.max( x, y );
    } // end method maximum

    public double minimum( double x, int y )
    {
    return min( x, y );
    } // end method minimum


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How can I debug this code?

    I don't understand exactly what you are asking. I use Netbeans and place break points wherever I need.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I debug this code?

    Use an IDE (NetBeans, Eclipse) and step through during the execution of the code.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,301
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: How can I debug this code?

    If you are just beginning, I would not recommend using an IDE. Add some println's within your code to let you evaluate the code (variable values, conditionals, etc...). This is quite possibly one of the most valuable debugging tools
    http://www.javaprogrammingforums.com...t-println.html

Similar Threads

  1. [SOLVED] Single step debug in Eclipse
    By Sharmeen in forum Java IDEs
    Replies: 1
    Last Post: October 20th, 2012, 09:42 AM
  2. can anyone help me please to debug my simple payroll java file?
    By breakzzzz20 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 14th, 2012, 06:48 PM
  3. How do I debug my Java applets to see what's going wrong?
    By diyaots in forum AWT / Java Swing
    Replies: 2
    Last Post: November 10th, 2011, 08:37 AM
  4. Pls help me to debug this code
    By coen1604 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 24th, 2011, 09:00 AM
  5. can someone help me debug plzz
    By andys in forum Object Oriented Programming
    Replies: 1
    Last Post: November 27th, 2010, 04:37 PM