Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class loopCounter {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner userInput = new Scanner(System.in);
  6.        
  7.         System.out.println("Enter the maximum value you want to count up to: ");
  8.         int countUpTo = userInput.nextInt();
  9.         double count = 0;
  10.        
  11.         for (int i = 1; i <= countUpTo; i++)
  12.         {
  13.             count += i;
  14.         }
  15.        
  16.         System.out.println("The sum is: " + count);
  17.         double average = count / countUpTo;
  18.         System.out.println("The average is : " + average);
  19.         userInput.close();
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement