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

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  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


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.