Of course, if you don't *HAVE* to display the sequence of integers--if you really only need the first and last numbers displayed along with the sum--then a bit of algebra will simplify the code:

Code:

public class SumConsecutiveNumbers
{
public static void main(String[] args)
{
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
if ( y < x ) /* would be a good idea to do this no matter what code is used */
{
x = y;
y = Integer.parseInt(args[0]);
}
System.out.println("The sum of " + x + " through " + y + " is " + ((x+y)*y)/2 );
}
}

Hmmm....come to think of it, *THIS* code does *NOT* need to do the swap on x and y if you code it thus:

Code:

public class SumConsecutiveNumbers
{
public static void main(String[] args)
{
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
System.out.println("The sum of " + x + " through " + y + " is "
+ ( ( x + y ) * ( x > y ? x : y ) / 2 );
}
}

Sneaky enough? (Well, not quite...doesn't work if the range is a negative number through a positive number.)