{"id":24021085,"url":"https://github.com/zipcodecore/sumofinput","last_synced_at":"2025-10-16T01:26:07.062Z","repository":{"id":39535117,"uuid":"105550118","full_name":"ZipCodeCore/SumOfInput","owner":"ZipCodeCore","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-07T17:13:56.000Z","size":26,"stargazers_count":0,"open_issues_count":23,"forks_count":64,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T21:15:09.277Z","etag":null,"topics":["corejava","corejava-chapter3"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZipCodeCore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-02T15:19:59.000Z","updated_at":"2025-02-07T17:14:00.000Z","dependencies_parsed_at":"2025-01-08T12:39:01.593Z","dependency_job_id":"f298415e-2899-4bdc-bd30-8b95df220b40","html_url":"https://github.com/ZipCodeCore/SumOfInput","commit_stats":null,"previous_names":["zipcodecore/sumofinput"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FSumOfInput","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FSumOfInput/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FSumOfInput/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FSumOfInput/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZipCodeCore","download_url":"https://codeload.github.com/ZipCodeCore/SumOfInput/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249153949,"owners_count":21221330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["corejava","corejava-chapter3"],"created_at":"2025-01-08T12:38:36.006Z","updated_at":"2025-10-16T01:26:01.994Z","avatar_url":"https://github.com/ZipCodeCore.png","language":"Java","readme":"# SumOfInput\n\n`fork` this repository and `clone` it to your local machine.\n\n# Sum the Numbers\n\n## **Objective:**\n\n* Write a program which prompts the user to input a number, `n`.\n* The program should respond by printing the sum of the numbers 1 to `n`.\n* **Constraint:** No [Guassian wizardry](https://letstalkscience.ca/educational-resources/backgrounders/gauss-summation) !\n\n### Extra Credit (no, not really)\n\n_If you find this lab to be super simple, then implment these two requirements._ If you're quite lost, skip them for now.\n\n* *Extra Credit* (get 256 pts) create a second method which USES the Gaussian Wizardry\n* **Extra EXTRA Credit** (32,767 pts) create a comparison of the two methods And *time them, showing which one is faster!!!*\n\n### **Purpose:**\n* To establish familiarity with\n    * Loops\n    * User input\n    * Object instantation/declaration\n    * Method invokation\n\n### Instructions\n\nFirst, `cd src/main/java` to get to the correct directory.\nUse `nano` to create a new Java file named `SumOfInput.java`.\n\n1. Create a new Java class named `SumOfInput`. (You can use the `javac` and `java` commands to compile and run your program.)\n2. Inside the `main` method of the `SumOfInput` class, create a new `Scanner` object to read user input.\n3. Prompt the user to enter a number, `n`, and read the input using the `Scanner` object.\n4. Create a new `sumNumbers()` method (hey, go find the one in JavaSmall) and pass the user input to the method.\n5. Inside the `sumNumbers()` method, use a loop to calculate the sum of the numbers from 1 to `n`. (If you didn't type it in from JavaSmall)\n6. Print the sum of the numbers to the console.\n\nNow, how do we run this java program?\n\n```bash\njavac SumOfInput.java\njava SumOfInput\n```\n\nDid it give you the right answer? If not, go back and fix it.\n(How do you know if it's right? Well, you can do the math yourself, or you can use the Gaussian Wizardry.)\nWe do know that the sum of the numbers from 1 to 3 is 6. So, if you input 3, you should get 6.\nNow, pick some bigger numbers and see if you get the right answer. What happens if you put in 199872?\n(Let's put a pin in that for now. I mean, of course, how did that sum end up being a negative number?)\n\nOakay, now, if you're feeling froggy, go ahead and do the Extra Credit.\nBut before you do that save all this work to your GitHub repository.\n\n```bash\ngit add .\ngit commit -m \"Add SumOfInput work\"\ngit push\n```\n\nNOW do the Extra Credit.\n\n\n### **Resources:**\n\nThis is a pretty advanced topic for this lab. Welcome to Zip Code.\n\n#### timing loops\n\nTo time two different Java loops, you can use the `System.currentTimeMillis()` method to get the current time in milliseconds before and after each loop, and then calculate the difference between the two times to get the elapsed time.\n\nHere is an example of how to time two different Java loops:\n\n```java\npublic class LoopTimingExample {\n    public static void main(String[] args) {\n        long startTime, endTime, elapsedTime;\n\n        // Loop 1\n        String foo = \"!\";\n        startTime = System.currentTimeMillis();\n        for (int i = 0; i \u003c 1000000; i++) {\n            // do something\n            foo = \"foo\" + foo + \"bar\";\n        }\n        endTime = System.currentTimeMillis();\n        elapsedTime = endTime - startTime;\n        System.out.println(\"Loop 1 elapsed time: \" + elapsedTime + \" ms\");\n\n        // Loop 2\n        String bar = \"^\";\n        startTime = System.currentTimeMillis();\n        for (int i = 0; i \u003c 10000000; i++) {\n            // do something else\n            bar = bar + \"bar \";\n        }\n        endTime = System.currentTimeMillis();\n        elapsedTime = endTime - startTime;\n        System.out.println(\"Loop 2 elapsed time: \" + elapsedTime + \" ms\");\n    }\n}\n```\nIn this example, two loops are timed using the System.currentTimeMillis() method. The elapsed time for each loop is calculated by subtracting the start time from the end time, and the result is output to the console.\n\nTiming Java loops can be useful for measuring the performance of different algorithms or code optimizations.\n\n## Unit Test\nNo Unit Tests (well, not yet).\n\n## What's a millisecond?\n\nA millisecond is a unit of time that is equal to one thousandth of a second. It is commonly used in computer programming to measure the duration of operations or to time events. For example, a program might measure the time it takes to perform a calculation in milliseconds, or it might use a delay of a certain number of milliseconds to control the timing of events. In general, a millisecond is a very short amount of time, but it can be significant in certain contexts, such as real-time systems or high-performance computing.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzipcodecore%2Fsumofinput","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzipcodecore%2Fsumofinput","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzipcodecore%2Fsumofinput/lists"}