Advertisement
CamiloCastilla

Untitled

Dec 12th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner keyboard = new Scanner(System.in);
  9.         System.out.println("Number:");
  10.         int count = keyboard.nextInt();
  11.         int sum=0;
  12.         for (int n = 1; n <= count; n++) {
  13.             System.out.print(n + "\t");
  14.             sum=sum+n;
  15.         }
  16.         System.out.println("The sum is " + sum);
  17.     }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement