Advertisement
IanO-B

Untitled

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