The Code Used:-
import java.util.*;
class RandomNumber
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.print("How many integers you have? ");
int n = scan.nextInt();
System.out.print("What are you ranges? ");
int min = scan.nextInt();
int max = scan.nextInt();
System.out.print("The generated odd numbers are ");
generateOdd(n,min,max);
System.out.println();
System.out.print("The generated even numbers are ");
generateEven(n,min,max);
}
public static void generateOdd(int n,int r1,int r2)
{
int count=1;
Random random = new Random();
while(count<=n)
{
int randomNum = random.nextInt((r2+1)-r1)+r1;
if(randomNum%2 != 0)
{
System.out.print(randomNum+" ");
count++;
}
}
}
public static void generateEven(int n,int r1,int r2)
{
int count=1;
Random random = new Random();
while(count<=n)
{
int randomNum = random.nextInt((r2+1)-r1)+r1;
if(randomNum%2 == 0)
{
System.out.print(randomNum+" ");
count++;
}
}
}
}
I hope you like the solution. In case of any doubts regarding the solution feel free to ask it in the comment section. If you like the solution please give a thumbs up.
java 1. Write an application that generates n random integers in the range provided the user....
In Java* Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...
2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...
Create a java class that user put two inputs and first input generate n length array of randomly generated numbers. and the second input changes that number of multiples in the array into zero. for example, if the user puts 3 and 5 then it generates 34 60 10 and since the second input is 5 then the multiple of 5 eliminates so it generates 34 0 0 here is the main method that I'm going to use class Main...
Java Programming - Write a program that generates two random integers, both in the range 25 to 75, inclusive. Use the Math class. Print both integers and then display the positive difference between the two integers, but use a selection. Do not use the absolute value method of the Math class.
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...
A. Create a java program that generates 1000 random integers. Write the 1000 random integers to a file using the Formatter class. B. Create a second java program that opens the file with the 1000 integers using the Scanner class. Read in the integers and find and print out the largest, smallest and the average of all 1000 numbers. C. Repeat A from above but use the BufferedWriter class B. Repeat B from above but use the BufferedReader class.
Part II. Write a programming segment that generates 25 random integers between 0 and 99. Place the even numbers in an array called EVEN and then place the odd numbers in an array called ODD. Print the EVEN array and Print the ODD array
Write a java program that asks the user to enter 2 integers, obtains them from the user, determines if they are even or odd numbers and prints their sum, product, difference, and quotient (Division).
/*Write a Java program that generates 1000 random integers, * calculates the average and prints two counts, one for the * numbers lower than the average and one for the numbers larger than the average. */ Use java thanks
(C++)Write a program that generates twenty five random integers between 0 and 24 and display the sum of even integers. (Hint: Use rand()%25 to generate a random integer between 0 and 24. Use an array of 25 integers, say num , to store the random integers generated between 0 and 24.)