Scanner in = new Scanner(System.in); int first = 0; int last = 0; int total = 0; int i = 0;
System.out.println("Hello. I will calculate the sum"); System.out.println("of consecutive integers."); System.out.println("Please enter the starting number:"); first = in.nextInt(); System.out.println("Please enter the ending number:"); last = in.nextInt();
while (last < first) { System.out.println(last + " is smaller than " + first); System.out.println("The ending number must be bigger than the first"); System.out.println("Enter the starting number again"); first = in.nextInt(); System.out.println("Enter the ending number again"); last = in.nextInt(); System.out.println("The sum of the numbers are " + total);
}
{ for (i = first; i <= last; i++)
total = total + i; } } }
although the code is fine with the way it is now, I need to be able to put another user defined method into this to get the answer...any ideas how it can be done..