006-001-011

For Loop: Calculate Sum

Medium

Problem Description

for loop: Calculate Sum

In this problem, you will create a program that reads an integer N from standard input, uses a for loop to accumulate integers from 1 to N, and displays the sum in the format "Sum: NN" to standard output.

Learning Objective: Understand how to perform cumulative calculations using for loops

Overview

Create a program that reads an integer N from standard input, then calculates and outputs the sum of integers from 1 to N.

Input Format

N
  • N: An integer upper bound for the sum (N >= 1)

Specifications

  • Use Scanner to read integer N
  • Use a for loop to iterate from 1 to N
  • Accumulate the sum inside the loop
  • Output the final sum

Output Format

Sum: NN

Example

Input: 10
Output: Sum: 55

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up