Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AddingValuesForLoop {
- public static void main(String args[]) {
- Scanner input = new Scanner(System.in);
- System.out.print("Number: ");
- int max = input.nextInt();
- int sum = 0;
- for(int i=1; i<=max; i++) {
- System.out.print(i + "\t");
- sum = sum + i;
- }
- System.out.print("\nThe sum is " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement