India's Largest Free Online Education Platform

java program to calculate average of 5 numbers

Java program to calculate average of 5 numbers

Code:

import java.util.Scanner;
import static java.lang.System.out;
public class AverageOfNumber
{      public static void main(String args[]) {
  
    Scanner Sc= new Scanner(System.in);
    
    out.println("Enter 1st number");
    float a=Sc.nextFloat();
   
     out.println("Enter 2nd number");
    float b=Sc.nextFloat();
    
    out.println("Enter 3rd number");
    float c=Sc.nextFloat();
    
    out.println("Enter 4th number");
    float d=Sc.nextFloat();
    
    out.println("Enter 5th number");
    float e=Sc.nextFloat();
    
    float avg= (a+b+c+d+e)/5;
    out.println("Calculated average sum of five numbers is: "+avg);
  }
}



Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!