Write a Java program that takes five numbers as input to calculate and print the average of the numbers


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Scanner;
  2.  
  3. public class Javaexcercise {
  4.  
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7.  
  8. System.out.print("Input 1st number: ");
  9. int num1 = in.nextInt();
  10.  
  11. System.out.print("Input 2nd number: ");
  12. int num2 = in.nextInt();
  13.  
  14. System.out.print("Input 3rd number: ");
  15. int num3 = in.nextInt();
  16.  
  17. System.out.print("Input 4th number: ");
  18. int num4 = in.nextInt();
  19.  
  20. System.out.print("Enter 5th number: ");
  21. int num5 = in.nextInt();
  22.  
  23.  
  24. System.out.println("Average of 5 numbers is: " +
  25. (num1 + num2 + num3 + num4 + num5) / 5);
  26. }
  27. }

Result

java techstudy.org

     





Related Topics




Popular Posts