Advertisement
shawonrog

Array sum/average

Feb 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package basicjavalipu2;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class BasicJavaLipu2 {
  7. public static void main(String[] args) {
  8. Scanner sc=new Scanner(System.in);
  9. double[] number=new double[5];
  10. double sum=0;
  11. System.out.println("please enter 5 numbers: ");
  12. for (int i = 0; i <number.length; i++) {
  13. number[i]=sc.nextDouble();
  14. }
  15. for (int i = 0; i <number.length; i++) {
  16. sum=sum+number[i];
  17. }
  18. System.out.println("Total Number is: "+sum);
  19. double ave=sum/number.length;
  20. System.out.println("\nAverage number: "+ave);
  21.  
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement