Thread: Number in Java
View Single Post
Old Mar 24th, 2008, 2:14 AM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Number in Java

Consider that the number of elements in the array will be abs(first-last) + 1.

I will try to keep this fairly vague since it seems you want to solve this problem yourself. For the loop, I would suggest using two variables as counters: one as an index into the array from 0 to the number of elements in the array - 1; and another for counting from the first to the last number in the set. (There are, as always, numerous ways to achieve the same goal.)

As for allowing user input in the format a...b, you could use StringTokenizer or Pattern and Matcher for regular expression matching.
titaniumdecoy is offline   Reply With Quote