Browse Source

Modified Main.java file to print sum of numbers 1 through an inputted number

Connor Dunnigan 6 years ago
parent
commit
3fe72fb97f
2 changed files with 16 additions and 6 deletions
  1. BIN
      Main.class
  2. 16
    6
      Main.java

BIN
Main.class View File


+ 16
- 6
Main.java View File

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