import java.util.Scanner;
public class Lab06Ex2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int a;
int b;
int c;
int d = 1;
System.out.println("Enter a number: ");
a = keyboard.nextInt();
System.out.println("Enter another number: ");
b = keyboard.nextInt();
while (a < B)
{
a += 1;
a = a + b;
System.out.print( a );
}
I am trying to write a program that asks the operator for two integers. I need to find the sum of all the integers between and including the 2 entered. I have been playing with this since 7:30 and I cannot get it to work correctly at all.
Ex. Operator enters 2 and 9. The system adds 2 + 3 + 4 + 5 +6 +8 + 9 and displays the answer, 44.
I just learned the while, do-while, and for loop on monday so this stuff is kind of new to me.
I cannot figure out the write algorithm to get it to add the numbers together. This is driving me nuts, it never works.
...sorry if this is not allowed.
This post has been edited by tcr071: 09 October 2007 - 07:59 PM

New Topic/Question
Reply




MultiQuote





|