Question
PP 2.2 Write an application that reads three integers and prints their average.
//********************************************************************
// Averageofthreeintegers.java
// CS151A, Assignment 2 PP 2.2
// This class calculates the average of three integers
//********************************************************************
import java.io.*;
import java.util.*;
public class Averageofthreeintegers
{
public static void main (String[] args)
{
int num1;
int num2;
int num3;
double Average;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the first number");
num1 = keyboard.nextInt();
System.out.println("Please enter the second number");
num2 = keyboard.nextInt();
System.out.println("Please enter the third number");
num3 = keyboard.nextInt ();
Average = (num1 + num2 + num3) / 3;
System.out.println ("Average: " + Average);
}
}
No comments:
Post a Comment