
Java Homework Help on RanNumGen and AndOp
- 26th May, 2022
- 15:37 PM
public class RanNumGen { public static void main(String[] args) { int n=Integer.parseInt(args[0]);//number of values int max=100;//macimum value of range int min=1;//minimum value of range int range = max - min + 1;//creating the range int rand; rand = (int)(Math.random() * range) + min; //generate a number in the specified range System.out.print(rand + " ");//print the number int minValue=rand;// let the first number be the minimum number int maxValue=rand;//let the first number be the maximum number for(int i=0;i rand = (int)(Math.random() * range) + min; //generate a number in the specified range System.out.print(rand + " ");//print the number minValue=Math.min(minValue, rand);//check which is minimum (minimum number or new generated number ) assign this value to minimum number maxValue=Math.max(maxValue, rand);//check which is maximum (maximum number or new generated number ) assign this value to maximum number } System.out.println(); System.out.println("The minimum value is "+minValue);//print minimum number System.out.println("The maximum value is "+maxValue);//print maximum number } } public class AndOp { public static void main(String[] args) { double value1=Double.parseDouble(args[0]);//first value double value2=Double.parseDouble(args[1]);//second value if((value1>0&&value1<1)&&(value2>0&&value2<1)){//check values lies b/w 0 and 1 System.out.println("True");//if it lies then print this } else{ System.out.println("False");//if not then print this } } }