troubleshooting Question

Issue With Subtraction example

Avatar of Computer Guy
Computer Guy asked on
22 Comments1 Solution103 ViewsLast Modified:

Using the following code, I am generating a subtraction problem.

I want the first number to be bigger than the first so it will not result to a negative.

This is what I have:

		Random r = new Random();
		int first = r.nextInt(9) + 1;
		int second = r.nextInt(9) + 1;
		while (second < first){
		second = r.nextInt(9);

				sum = first - second;
Neil Russell
Solution Development Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 22 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros