Question: isArithmetic public static boolean isArithmetic(java.lang.String text) **setDelimiter(,) i must use this Given a string of text containing numbers separated by commas, returns true if the
isArithmetic
public static boolean isArithmetic(java.lang.String text)
**setDelimiter(",") i must use this
Given a string of text containing numbers separated by commas, returns true if the numbers form an arithmetic sequence (a sequence in which each value differs from the previous one by a fixed amount). For example,
- given "2,4,6,8", the method returns true
- given "-2,5,12,19,26", returns true
- given "2,4,7", returns false
- given "1,2,23skidoo", returns false
The method should return true for any string containing two or fewer numbers and false for any invalid string. Assume that the string does not contain whitespace before or after the comma.
Parameters:
text - a string of text containing numbers separated by commas
Returns:
true if each number differs from the previous one by the same amount
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
