import cs1.Keyboard;
/**
Calculate the sum of numbers from a to b step c.
@author Greg Vogl
last modified 2003-09-22
*/
public class Sumabc
{
/**
Calculate the sum of numbers from a to b step c.
input: float a, b, c
output: sum from a to b step c
@throws IOException to handle bad input
*/
public static void main (String[] args)
{
// get input
System.out.println("This program calculates the sum of numbers from a to b step c.");
System.out.println("Enter float a and press Enter.");
float a = Keyboard.readFloat();
System.out.println("Enter float b and press Enter.");
float b = Keyboard.readFloat();
System.out.println("Enter float c and press Enter.");
float c = Keyboard.readFloat();
// calculate statistics
float sum = 0;
for (float f = a; f <= b; f += c)
sum += f;
// output results
System.out.println(sum + "\tSum");
}
}