Witam wszystkich
//average program with sentinel controlled repition
import java.util.Scanner;
class Milage
{
public static void main (String args [])
{
Scanner myinput = new Scanner(System.in);
int Counter;
int tank;
int total;
int milage;
double average;
//initialization phase
total = 0;
Counter = 0;
//processing phase
//prompts to user to input size of tank
System.out.print("Enter size of you tank in gallons: ");
tank = myinput.nextInt();
System.out.print("Enter Your mialage: -1 to Quit: ");
milage = myinput.nextInt();
while (milage != -1) //check for valid input
{
//add grade to total
total = total + milage;
//avrmile = avrmile + milage;
//add 1 to grade counter
Counter = Counter + 1;
System.out.print("Enter Your mialage: -1 to Quit: ");
milage = myinput.nextInt();
}
//display message
if (Counter != 0)
{
average = (double)total/tank;
System.out.println("The average milage per gallon is: "+average);
}
else
System.out.println("No milage were entered ");
}
}
Czy ten program jest jezeli chodzi o przeliczenia dobrze napisany ? nie jestem na 100% przekonany.
Z góry dzieki
Pozdrawiam