1234567891011121314151617181920 |
- import java.util.Scanner;
-
- public class Main{
-
- public static void main(String[] args){
-
- Scanner stdin = new Scanner(System.in);
-
- int num, sum = 0;
-
- System.out.println("Please enter a number");
- num = stdin.nextInt();
-
- for(int i=1; i<=num; i++){
- sum+=i;
- }
- System.out.println("The sum of the numbers 1 to " + num + " = " + sum);
- }
- }
|