0

Directions...Write a program SumOfOdds that has one main method that asks the user to input two odd integers where the first is smaller than the second. The program ouputs the sum of all the odd integers from the smaller output to the larger output. You must use a while loop for this program.:)

public class SumOfOdds {

    public SumOfOdds(int input1, int input2)
    {
		x = input1;
		y = input2;
    }
    while (x<y)
    {

    }
	private int x;
	private int y;
}

This is what I have so far..not much.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by TigerTeck
0

firstly, you are supposed to have one

main

method in which you prompt the user
to enter the values

int num1; //first number which should be smaller
  int num2; //second value which should be bigger than the first.

check if numbers are odd

if (num1%2=1)&&(num2%2=1)

then you can write your while loop

while(num1<num2)
0

I am going to prompt the user to input the values in the tester class. Im still confused on the while loop summing up all consecutive odd int.'s.

public class SumOfOdds {

    public SumOfOdds(int input1, int input2)
    {
		num1 = input1;
		num2 = input2;
    }
    int num1;
    int num2;
    if (num1%2=1)&&(num2%2=1)
    	while (num1<num2)
    	{
    		int sum = sum
		}
	private int num1;
	private int num2;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.