Advertisement
Vladkoheca

AvgOfASeriesOfNums.java

Oct 25th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AvgOfASeriesOfNums {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.  
  7.         System.out.print("Enter the number of values: ");
  8.         int numValues = sc.nextInt();
  9.         double sumOfValues = 0;
  10.         for (int i = 1; i <= numValues; i++) {
  11.             System.out.print("Enter value " + i + ": ");
  12.             double value = sc.nextInt();
  13.             sumOfValues += value;
  14.         }
  15.      double avg = sumOfValues / numValues;
  16.         System.out.println("The average is: " + avg);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement