I have completed the following code, compiled it with no errors and ran it with no problems. However, here are the parameters for the assignment and I cannot return an answer every time without getting a negative number in at least one operation. What am I missing?????
Write a program in Java language that outputs to the screen the result of Subtraction and Division of two numbers.
The two numbers must be declared as integer data types and must be generated using the random number generator function
The range of the values must be between 1 and 50.
Special requirements for the two numbers are that their difference can not be negative
Here is the code that I created:
//***************************************************************
// MathOps3.java Author:
//
// A Java program that outputs, to the screen,
// the results of subtraction and division of two random numbers
//***************************************************************
import java.text.*;
import java.util.*;
public class MathOps3
{
public static void main(String[] args)
{
Random rand = new Random();
{
int numb1 = (rand.nextInt(50))+1;
int numb2 = (rand.nextInt(50))+1;
int subtraction = numb2-numb1;
int subtraction1 = numb1-numb2;
int modulus = numb1%numb2;
int modulus1 = numb2%numb1;
int quotient = numb1/numb2;
int quotient1 = numb2/numb1;
System.out.println("\nnumber1 and number2 are: " +numb1+" and "+numb2);
//------------------------------------------
for (int n= 0; n<5; n++);
//------------------------------------------
if (numb2<numb1);
{
subtraction = numb2-numb1;
}
System.out.println("The answer will be:" +subtraction);
//------------------------------------------
if (numb1<numb2);
{
subtraction1 = numb1-numb2;
}
System.out.println("Your answer is:" +subtraction1);
//------------------------------------------
if (numb1<numb2);
{
modulus = numb1%numb2;
}
System.out.println("The answer is:" +modulus);
//-------------------------------------------
if (numb2<numb1);
{
modulus1 = numb2%numb1;
}
System.out.println("The result will be:" +modulus1);
//-------------------------------------------
if (numb1<numb2);
{
quotient = numb1/numb2;
}
System.out.println("The result is:" +quotient);
//-------------------------------------------
if (numb2<numb1);
{
quotient1 = numb2/numb1;
}
System.out.println("The answer is:" +quotient1);
//-------------------------------------------
}
}
}
I'm not looking for anyone to give me the answer, just point me in the right direction so I can find & figure it out. Thanks in advance.