java - how to make collapse number with hypen -
i want create number in collapse format hypen symbol.
suppose input "1,2,4,6,7,8,9,11,12,14,16,17,18,19"
and want output below "1-2,4,6,7-9,11-12,14,16-19
this sounds homework question me, i'll @ to the lowest degree point in right direction.
personally utilize stringtokenizer , split string integer array. loop through array , checking if contents of current position related next position or not, find way save values , print them later. might require sec loop print later, think creative , find solution faster single loop. ;)
if want fancy, might take recursion , seeing if can using single function , string.
hope find helpful , sends in right direction.
java
No comments:
Post a Comment