# Thread: Need help with writing an integer program with jGrasp

1. Member
Join Date
Oct 2011
Posts
2
Rep Power
0

## Need help with writing an integer program with jGrasp

INSTRUCTIONS
You will create a program that will sum the odd integers from 3 to whatever a user inputs. And you will create a loop to do it repeatedly. To do this:
//-1 Ask the user for a positive integer value greater than 2
//-2 Check if the user input is 3 or higher, if it is less than 3 print an error message
//-3 Else if the user input is 3 or higher create a for loop that will keep a sum of the odd numbers between 3 and the input value. Print out the sum included in an explicit statement showing the starting (3) and ending numbers (user input value).
//-4 Ask the user if they want to try another number. Scan in the response, while it is "yes" repeat from step 1, if the response is "no" end the program by saying "Thanks for playing!"

Also remember that since the sentinel value is "yes"; a string needs to use name.equals rather than name= to evaluate whether the sentinel is found. This helps start the while loop.
To do your for loop don't forget to start your count at 3 and then since we are only adding odd values make the increment add 2.

Example output:
Enter a positive integer: 0
The value must be greater than two.
Do you want to do another? yes or no
yes
Enter a positive integer: 10
The sum of the ODD integers from 3 to 10 is 24
Do you want to do another? yes or no
no
Thanks for playing!

I cannot seem to get the boolean part right and have it loop again. I do not think I have my 'do' statement correct as well.

This is what i have so far:
PHP Code:
```import java.util.Scanner;
import java.lang.String;

public class test4
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);

int userNum, total = 0;
String playAgain;
boolean play;

while (play == true);
{
System.out.println("Enter a positive integer: ");
userNum = scan.nextInt();
}
if (userNum >= 3)
{
for(int count = 3; count < userNum; count +=2)
{
total = total + count;
}

System.out.println("The sum of the ODD integers from 3 to " + userNum +  " is " + total);
}
do
{
System.out.println("Do you want to do another? yes or no");
playAgain = scan.nextLine();

if (playAgain.equals("yes"))
play = true;
if (playAgain.equals("no"))
play = false;
else

if (userNum < 3)
System.out.println("The value must be greater than two");
}

}
}```
Some help would be great. Thanks!

2. Member
Join Date
Oct 2011
Posts
2
Rep Power
0

## Re: Need help with writing an integer program with jGrasp

need this tomorrow by 1 pm :( i believe my end brackets are off too

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•