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
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.
Re: How can I debug this code?
Use an IDE (NetBeans, Eclipse) and step through during the execution of the code.
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