


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....
Please write in java program Write an application that generates 100 random integers between 1 and 75 and writes them to a file named "file_activity.txt". Read the data back from the file and display the following: The sum of the numbers in the file The average of the numbers in the file The numbers in the file in increasing order To sort an array: int[] arr = new int[20]; Arrays.sort(arr); -- this sorts an array To sort an ArrayList: ArrayList<Integer>...
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...
Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number). (1) Prompt for the user to input an integer and output the integer. (1 pts) Enter an integer: You entered: 5 (2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)...
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...
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.
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 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 program in Visual C# that generates 1000 random numbers with a user provided seed and upper limit on the random numbers generated. The numbers should be stored in a text file, each appearing on a newline, using the Windows Save File dialog. Each number should be separated by a newline.