Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Sum {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int num = scanner.nextInt();
  7. int result = 0;
  8.  
  9. if(num > 0) {
  10. for (int i = 1; i <= num; i++) {
  11. result += i;
  12. }
  13. System.out.println(result);
  14. } else {
  15. for (int i = num; i <=1 ; i++) {
  16. result += i;
  17. }
  18. System.out.println(result);
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement