Monthly Archives: February 2014
Write a program that takes two int values a and b from the command line and prints a random integer between a and b.
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
}
}
Wind chill
Given the temperature t (in Fahrenheit) and the wind speed v (in miles per hour), the National Weather Service defines the effective temperature (the wind chill) to be:
w = 35.74 + 0.6215 t + (0.4275 t – 35.75) v0.16
Write a program WindChill.java that takes two double command-line arguments t and v and prints out the wind chill. Use Math.pow(a, b) to compute ab. Note: the formula is not valid if t is larger than 50 in absolute value or if v is larger than 120 or less than 3 (you may assume that the values you get are in that range).