Main.java 660B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Created by iyasuwatts on 10/17/17.
  3. */
  4. import java.util.*;
  5. public class Main {
  6. private static int num;
  7. public Main(int n){
  8. }
  9. /*public static int getN(){
  10. return n;
  11. }
  12. public static void setN(int a){
  13. n=a;
  14. } */
  15. public static void main(String[] args){
  16. //setN(0);
  17. Scanner input = new Scanner(System.in);
  18. System.out.println("Please enter a number");
  19. int num = input.nextInt();
  20. int sum = 0;
  21. for(int i = num; i>=1; i--){
  22. sum += i;
  23. }
  24. System.out.println("sum of 1 to " + num + " is " + sum);
  25. }
  26. }