File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ /**
4
+ * Have the function SimpleAdding(num) add up all the numbers from 1 to num.
5
+ * For example: if the input is 4 then your program
6
+ * should return 10 because 1 + 2 + 3 + 4 = 10.
7
+ * For the test cases, the parameter num will be any number from 1 to 1000.
8
+ */
9
+ public class SimpleAdding {
10
+
11
+ /**
12
+ * Simple Adding function.
13
+ *
14
+ * @param num input number
15
+ * @return the sum of numbers
16
+ */
17
+ private static int simpleAdding (int num ) {
18
+ return num * (num + 1 ) / 2 ;
19
+ }
20
+
21
+ /**
22
+ * Entry point.
23
+ *
24
+ * @param args command line arguments
25
+ */
26
+ public static void main (String [] args ) {
27
+ var result1 = simpleAdding (100 );
28
+ System .out .println (result1 );
29
+ var result2 = simpleAdding (8 );
30
+ System .out .println (result2 );
31
+ }
32
+
33
+ }
You can’t perform that action at this time.
0 commit comments