Quantcast
Channel: Rant4u » Java programming
Viewing all articles
Browse latest Browse all 3

Write a program that takes two int values a and b from the command line and prints a random integer between a and b.

$
0
0

import java.lang.Math;
import java.util.Scanner;

public class RandomNumbers{

public static void main(String args[])
{
System.out.println(“Enter a number “); //This prompts the user to enter a number
Scanner scan = new Scanner(System.in);
double t = scan.nextDouble(); //Stores the valuse as a double

System.out.println(“Enter a second number “); //This prompts the user to enter a 2nd number
double v = scan.nextDouble(); //Stores the valuse as a double

double w = Math.floor(Math.random()*(t-v+1)+v); //assigns w to a random number in between t & v
System.out.println(w); //prints w

}
}



Viewing all articles
Browse latest Browse all 3

Trending Articles