12345678910111213141516171819202122
  1. /**
  2. * Created by Thuy Khong.
  3. */
  4. import java.util.Scanner;
  5. public class Main {
  6. public static void main(String[] args){
  7. Scanner scan = new Scanner(System.in);
  8. System.out.println("Please enter a number.");
  9. int number = scan.nextInt();
  10. int sum = 0;
  11. for (int i = 0; i<= number; i++) {
  12. sum = sum + i;
  13. }
  14. System.out.println("The sum of the numbers 1 to " + number + " is " + sum);
  15. }
  16. }