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.

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)

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.