Skip to content

esotericbug/string-calculator-kata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Calculator

A Simple String Calculator Kata

Steps:

  1. Create a simple String calculator with a method signature like this:

Input: a string of comma-separated numbers Output: an integer, sum of the numbers Examples:

Input: “”, Output: 0 Input: “1”, Output: 1 Input: “1,5”, Output: 6 2. Allow the add method to handle any amount of numbers.

  1. Allow the add method to handle new lines between numbers (instead of commas). ("1\n2,3" should return 6)

  2. Support different delimiters:

To change the delimiter, the beginning of the string will contain a separate line that looks like this: "//[delimiter]\n[numbers…]". For example, "//;\n1;2" where the delimiter is ";" should return 3.

  1. Calling add with a negative number will throw an exception: "negative numbers not allowed <negative_number>".

If there are multiple negative numbers, show all of them in the exception message, separated by commas.

How to run

The program requires Java 17.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages