Skip to content

Easy challenges - part 2 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Aug 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simple Adding
  • Loading branch information
ardallie committed Aug 15, 2021
commit 131c9b59abd5f60364144864f0630695d6bfdd39
33 changes: 33 additions & 0 deletions src/easy/SimpleAdding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package easy;

/**
* Have the function SimpleAdding(num) add up all the numbers from 1 to num.
* For example: if the input is 4 then your program
* should return 10 because 1 + 2 + 3 + 4 = 10.
* For the test cases, the parameter num will be any number from 1 to 1000.
*/
public class SimpleAdding {

/**
* Simple Adding function.
*
* @param num input number
* @return the sum of numbers
*/
private static int simpleAdding(int num) {
return num * (num + 1) / 2;
}

/**
* Entry point.
*
* @param args command line arguments
*/
public static void main(String[] args) {
var result1 = simpleAdding(100);
System.out.println(result1);
var result2 = simpleAdding(8);
System.out.println(result2);
}

}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy