Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Sum {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = scanner.nextInt();
- int result = 0;
- if(num > 0) {
- for (int i = 1; i <= num; i++) {
- result += i;
- }
- System.out.println(result);
- } else {
- for (int i = num; i <=1 ; i++) {
- result += i;
- }
- System.out.println(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement