Main.java 349B

1234567891011121314151617181920
  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args){
  4. Scanner stdin = new Scanner(System.in);
  5. int num, sum = 0;
  6. System.out.println("Please enter a number");
  7. num = stdin.nextInt();
  8. for(int i=1; i<=num; i++){
  9. sum+=i;
  10. }
  11. System.out.println("The sum of the numbers 1 to " + num + " = " + sum);
  12. }
  13. }