Java random numbers classification

Write a program that generates 60 pairs of random integer (int) values with values between 1 and 10,0000. For each generated pair, use an if-else statement to classify the first value as greater than, less than, or equal to the second value. For output, display BOTH generated values as well as the classification in the format “Number 1 Number 2″, one number pair per output line, where is “less than”, “equals” or “greater than”. – asked by Raj on our Facebook profile

package com.itcuties.questions;
import java.util.Random;

public class Answer {
	public static void main(String[] args) {
		Random random = new Random();
		for (int i=0; i < 60; i++) {
			int rand1 = random.nextInt(10000)+1;
			int rand2 = random.nextInt(10000)+1;
			if (rand1 < rand2) {
				System.out.println(rand1 + " less than " + rand2);
			} else if (rand1 == rand2) {
				System.out.println(rand1 + " equals " + rand2);
			} else {
				System.out.println(rand1 + " greater than " + rand2);

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>