Java program to have random number(s) within a specified limit


package com.physicsinfo;

import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        System.out.print("Enter the highest integer within which you want the random number: ");
        Scanner sc = new Scanner(;
        int highest = sc.nextInt();
        System.out.print("How many random numbers do you want to have printed: ");
        int count = sc.nextInt();
        double rand;
        System.out.println("Here is/are your random number(s): ");
        for(int i=1;i<=count;i++) {
            rand = highest * Math.random();
            System.out.print((int)rand+" ");
                System.out.println(" ");


Java random number program output

Leave a Comment

Your email address will not be published.