Sunday, September 10, 2017

Average Calculator

Challenge: Write a program that prompts the user for two doubles and then prints their average.


import java.util.*;

class lab2_2{

public static void main(String[]args)
Scanner in=new Scanner(;
System.out.println("***Two numbers Average Calculator***");

System.out.println("Enter the first number:");
double firstNumber=in.nextDouble();
System.out.println("Enter the second number:");
double secondNumber=in.nextDouble();
double average =(firstNumber+secondNumber)/2;
System.out.println("The average is: "+average);


This program is a continuation of the previous one, but here we are going to use a different type of variable and we are going to implement an arithmetic operator (+). First let the user know this program is a two numbers average calculator and we request both numbers'values using the Scanner method. After both values are entered we perform the average operation and output the result to the user.

No comments:

Post a Comment