How do I generate two number so that the result of division is an integer?
<p>I am trying to generate two numbers so that the division result is an integer, not a double, for example: 2/2=1; 30/3=10; etc... I do not want something like this: 14/5=2.8; 18/7=2.57..etc.  Please help.  Thanks in advance.</p>

<pre><code>package number;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.*;

public class IntergerNumber extends JFrame implements ActionListener
{
JLabel lblFirstNum = new JLabel("");
JLabel lblSecondNum = new JLabel("");
JLabel lblOperator = new JLabel("/");
JTextArea taResult = new JTextArea();
JButton bCheck = new JButton("Check");
JPanel pOperator = new JPanel();
JPanel pButton = new JPanel();

public IntergerNumber()
{
pOperator.setLayout(new GridLayout(3, 2));
pOperator.add(new JLabel());
pOperator.add(lblFirstNum);
pOperator.add(lblOperator);
pOperator.add(lblSecondNum);
pOperator.add(new JLabel());
pOperator.add(taResult);
pButton.add(bCheck);
initializeComponents();
generateRanDomNumber();
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(pOperator, BorderLayout.CENTER);
this.getContentPane().add(pButton, BorderLayout.SOUTH);
}

private void generateRanDomNumber() 
{
// TODO Auto-generated method stub
Random randomGenerator = new Random();
int randomInt2 = 0;
int randomInt1 = randomGenerator.nextInt(50)%20;
if(randomInt1 == 0)
{
randomInt1 = randomGenerator.nextInt(50)%20;
}
while((randomInt1%2) != 0) //this will avoid odd number
{
randomInt1 = randomGenerator.nextInt(50)%2;
if(randomInt1 == 0)
{
randomInt1 = randomInt1 + 2;
}
}
randomInt2 = randomGenerator.nextInt(50)%2;
if(randomInt2 == 0)
{
randomInt2 = randomGenerator.nextInt(50)%20;
}
while((randomInt2%2) != 0)
{
randomInt2 = randomGenerator.nextInt(50)%2;
if(randomInt2 == 0)
{
randomInt2 = randomGenerator.nextInt(50)%20;
}
}

if(randomInt1 &gt;= randomInt2 &amp;&amp; randomInt2 != 0)
{               
System.out.println("====================");
System.out.println("First number is: " + randomInt1);
System.out.println("Second number is: " + randomInt2);
double x = randomInt1/randomInt2;
System.out.println("X is: " + x);
System.out.println("====================");
lblFirstNum.setText("" + randomInt1);
lblSecondNum.setText("" + randomInt2);
}
else if(randomInt1 &lt; randomInt2 &amp;&amp; randomInt1 != 0)
{               
System.out.println("====================");
System.out.println("First number is: " + randomInt1);
System.out.println("Second number is: " + randomInt2);
double x = randomInt2/randomInt1;
System.out.println("X is: " + x);
System.out.println("====================");
lblFirstNum.setText("" + randomInt2);
lblSecondNum.setText("" + randomInt1);
}
}

private void initializeComponents() 
{
// TODO Auto-generated method stub
lblOperator.setHorizontalAlignment(JLabel.RIGHT);
lblOperator.setFont(new Font("Arial", Font.BOLD, 40));
taResult.setBackground(Color.white);
taResult.setFont(new Font("Arial", Font.BOLD, 40));
taResult.setOpaque(true);       
lblFirstNum.setHorizontalAlignment(JLabel.CENTER);
lblFirstNum.setFont(new Font("Arial", Font.BOLD, 40));
lblSecondNum.setHorizontalAlignment(JLabel.CENTER);
lblSecondNum.setFont(new Font("Arial", Font.BOLD, 40));
bCheck.addActionListener(this);
taResult.setFocusable(true);
taResult.requestFocus();
}

@Override
public void actionPerformed(ActionEvent ae) 
{
// TODO Auto-generated method stub
if(ae.getSource().equals(bCheck))
{
String sFirstNum = lblFirstNum.getText();
String sSecondNum = lblSecondNum.getText();
String sResult = taResult.getText();
int first = Integer.parseInt(sFirstNum);
int second = Integer.parseInt(sSecondNum);
int result = Integer.parseInt(sResult);
if((first/second) == result)
{
System.out.println("Correct Answer");
taResult.setText("");
generateRanDomNumber();
taResult.setFocusable(true);
taResult.requestFocus();
}
else
{
System.out.println("Wrong Answer");
taResult.setText("");
generateRanDomNumber();
taResult.setFocusable(true);
taResult.requestFocus();
}
}
}
public static void main(String[] s)
{
IntergerNumber in = new IntergerNumber();
in.setVisible(true);
in.setSize(200,200);
in.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
</code></pre>
