Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class loopCounter {
- public static void main(String[] args) {
- Scanner userInput = new Scanner(System.in);
- System.out.println("Enter the maximum value you want to count up to: ");
- int countUpTo = userInput.nextInt();
- double count = 0;
- for (int i = 1; i <= countUpTo; i++)
- {
- count += i;
- }
- System.out.println("The sum is: " + count);
- double average = count / countUpTo;
- System.out.println("The average is : " + average);
- userInput.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement