006-001-013
Basic For Loop
Easy
Problem Description
Basic for loop
In this problem, you will create a program that reads N from standard input, uses a for loop to display numbers 1 through N sequentially, and calculates their sum.
Learning Objective: Understand the basics of repetitive processing with Java for loops
Overview
The for loop repeats processing a specified number of times. It consists of three parts: initialization, condition, and update expressions.
Input
N
- N: upper bound of the iteration (positive integer)
Specifications
- Read N from standard input
- Use a for loop to display numbers 1 through N
- Use a for loop to calculate and display the sum of 1 through N
Output Format
1
2
...
N
Sum: [total]
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