vendredi 24 février 2017

Generate random numbers in a specified range [on hold]

I cant seem to figure this out. I can generate a single random number, but when I try to do it multiple times with different parameters each time, I get errors. I am a beginner, but can someone help me with this problem?

Write a Java program (name it RandomNumbers) that generates random numbers as follows. Make sure to properly label your output for each part below and print the outputs on separate lines. As in the previous program, use the tab escape character to line-up the outputs after the labels. a) A random integer number between 30 and 50 (inclusive). b) A random integer number between 20 and -20 (inclusive). c) A random integer number between -20 and -60 (inclusive). d) A random floating-point number between 0.0 and 15.9999 (inclusive).

This is what I have so far:

public class RandomNumbers{

public static void main(String[] args) {

    int min = 30, max = 50;

    System.out.println("a) Random integer between 30 and 50 (inclusive): " +
            30 + (int)(Math.random() * ((50 - 30) + 1)));
}}




Aucun commentaire:

Enregistrer un commentaire