Write a Java program to input 5 numbers from keyboard and find their sum and average


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. public class JavaExcercise {
  3.  
  4. public static void main(String[] args)
  5.  
  6. {
  7. int i,numbers=0,sum=0;
  8. double avg;
  9. {
  10.  
  11. System.out.println("Enter any 5 numbers : ");
  12.  
  13. }
  14. for (i=0;i<5;i++)
  15. {
  16. Scanner in = new Scanner(System.in);
  17. numbers = in.nextInt();
  18.  
  19. sum +=numbers;
  20. }
  21. avg=sum/5;
  22. System.out.println("The sum of 5 no is : " +sum+"\nThe Average is : " +avg);
  23.  
  24. }
  25. }

Result

java techstudy.org

     





Related Topics




Popular Posts