Demetrius Murray 6 vuotta sitten
vanhempi
commit
d112eb0bbf
7 muutettua tiedostoa jossa 63 lisäystä ja 10 poistoa
  1. BIN
      Main.class
  2. 5
    0
      Main.ctxt
  3. 7
    0
      Main.java
  4. BIN
      Sum.class
  5. 5
    0
      Sum.ctxt
  6. 26
    0
      Sum.java
  7. 20
    10
      package.bluej

BIN
Main.class Näytä tiedosto


+ 5
- 0
Main.ctxt Näytä tiedosto

@@ -0,0 +1,5 @@
1
+#BlueJ class context
2
+comment0.target=Main
3
+comment1.params=args
4
+comment1.target=void\ main(java.lang.String[])
5
+numComments=2

+ 7
- 0
Main.java Näytä tiedosto

@@ -1,9 +1,16 @@
1 1
 /**
2 2
  * Created by iyasuwatts on 10/17/17.
3 3
  */
4
+import java.util.Scanner;
4 5
 public class Main {
5 6
 
6 7
     public static void main(String[] args){
8
+        System.out.println("\nGreetings! Let's do some math. Enter a number below to find the sum of all integers from \"1\" to \"n\"!\n");
9
+
10
+        Sum sum = new Sum();
11
+        sum.sumOfNumbers();
12
+        
13
+        System.out.println("\nWell... goodbye");
7 14
 
8 15
     }
9 16
 }

BIN
Sum.class Näytä tiedosto


+ 5
- 0
Sum.ctxt Näytä tiedosto

@@ -0,0 +1,5 @@
1
+#BlueJ class context
2
+comment0.target=Sum
3
+comment1.params=
4
+comment1.target=void\ sumOfNumbers()
5
+numComments=2

+ 26
- 0
Sum.java Näytä tiedosto

@@ -0,0 +1,26 @@
1
+import java.util.Scanner;
2
+
3
+public class Sum{
4
+    public void sumOfNumbers(){
5
+        int result = 1;
6
+        int i = 2;
7
+        
8
+        StringBuilder fact = new StringBuilder("1");
9
+
10
+        Scanner s = new Scanner(System.in);        
11
+        int input = s.nextInt();
12
+
13
+        if(input != 0){
14
+            
15
+            while(i <= input){
16
+                fact.append(String.format(" + %d", i));
17
+                result += i;
18
+                i++;
19
+            }
20
+
21
+            System.out.println(String.format("\nHmmm... the answer to that is..\n" + fact.toString() + "\nWhich is " + result + "!", input));
22
+            System.out.println("\nGot anything harder?\n\nIf not, you can enter '0' to close\n----------\n");
23
+            sumOfNumbers();
24
+        }
25
+    }
26
+}

+ 20
- 10
package.bluej Näytä tiedosto

@@ -1,20 +1,23 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=0
3
-editor.fx.0.width=0
4
-editor.fx.0.x=0
5
-editor.fx.0.y=0
2
+dependency1.from=Main
3
+dependency1.to=Sum
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=716
6
+editor.fx.0.width=800
7
+editor.fx.0.x=480
8
+editor.fx.0.y=23
6 9
 objectbench.height=164
7 10
 objectbench.width=776
8 11
 package.divider.horizontal=0.6
9 12
 package.divider.vertical=0.6845018450184502
10 13
 package.editor.height=364
11 14
 package.editor.width=674
12
-package.editor.x=-816
13
-package.editor.y=445
15
+package.editor.x=100
16
+package.editor.y=100
14 17
 package.frame.height=600
15 18
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=1
19
+package.numDependencies=1
20
+package.numTargets=2
18 21
 package.showExtends=true
19 22
 package.showUses=true
20 23
 project.charset=UTF-8
@@ -24,9 +27,16 @@ readme.width=47
24 27
 readme.x=10
25 28
 readme.y=10
26 29
 target1.height=50
27
-target1.name=Main
30
+target1.name=Sum
28 31
 target1.showInterface=false
29 32
 target1.type=ClassTarget
30 33
 target1.width=80
31
-target1.x=70
34
+target1.x=160
32 35
 target1.y=10
36
+target2.height=50
37
+target2.name=Main
38
+target2.showInterface=false
39
+target2.type=ClassTarget
40
+target2.width=80
41
+target2.x=70
42
+target2.y=10