We help IT Professionals succeed at work.

How do I edit my program to print out numbers with 1, 3, 5, 7, and 9 in them?

Erika Her asked
on
106 Views
Last Modified: 2017-03-30
The end goal for my program is to have the user input two integers, and then to print out ALL positive integers between those numbers. Not only do they have to be POSITIVE, but the numbers that are printed out should also have 1, 3, 5, 7 and 9 in them. If they don't, then that number is skipped and the program continually checks until the range is met.

``````import java.util.Scanner;

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

int numOne = -1;
int numTwo = -1;

boolean sameNumbers = true;
while (sameNumbers)
{
numOne = input.nextInt();
numTwo = input.nextInt();
if (numOne == numTwo)
{
System.out.println("Distinct integers required.");
}
else if (numOne != numTwo)
{
sameNumbers = false;
}
}

while (numOne != numTwo)
{
if (numOne < numTwo)
{
numOne++;
if (numOne > 0)
{
System.out.println(numOne);
}
}
else if (numOne > numTwo)
{
numTwo++;
if (numTwo > 0)
{
System.out.println(numTwo);
}
}
}

//we only want numbers with odd sig numbers in it 1, 3, 5, 7, 9.
System.out.println("Done. Normal termination.");

}
}
``````
Comment
Watch Question

View Solutions Only

Commented:
If they don't, then that number is skipped and the program continually checks until the range is met.

Until what range is met by whom? Why aren't you checking for positive? Is the lower bound supposed to be exclusive and the upper bound inclusive? Where's the requirement for distinct integers?
Software & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
Information Technology Specialist
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
Software & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Sufficient solutions provided by all experts
CERTIFIED EXPERT
Top Expert 2016

Commented:
:)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

• Troubleshooting
• Research
• Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the