1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ira Lisetskai [31]
3 years ago
13

You are asked to write a program that prompts the user for the size of two integer arrays, user input for the size must not exce

ed 50, you must validate this. We will use these arrays to represent our sets. These arrays will be randomly populated in the range that is 1 through double the size of the array. So if the array is of size 20, you will randomly populate it with values in the range 1-40 inclusive.
Computers and Technology
1 answer:
Zielflug [23.3K]3 years ago
4 0

Answer:

In Java:

import java.util.*;

public class MyClass{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 System.out.print("Length of array 1: ");

 int lent1 = input.nextInt();

 while(lent1 <= 0 || lent1 > 50){

     System.out.print("Length of array 1: ");

     lent1 = input.nextInt();

 }

 int[] array1 = new int[lent1];

 System.out.print("Length of array 2: ");

 int lent2 = input.nextInt();

 while(lent2 <= 0 || lent2 > 50){

     System.out.print("Length of array 2: ");

     lent2 = input.nextInt();

 }

 int[] array2 = new int[lent2];

 for(int i =0;i<lent1;i++){

     array1[i] = (int)(Math.random() * (lent1*2) + 1);

 }

 for(int i =0;i<lent2;i++){

     array2[i] = (int)(Math.random() * (lent2*2) + 1);

 }

 System.out.print("Array 1: ");

 for(int i =0;i<lent1;i++){

     System.out.print(array1[i]+" ");

 }

 System.out.println("Array 2: ");

 for(int i =0;i<lent2;i++){

     System.out.print(array2[i]+" ");

 }

}

}

Explanation:

This prompts the user for length of the first array

 System.out.print("Length of array 1: ");

This declares and gets input for the length of the first array

 int lent1 = input.nextInt();

This validates the length of first array

<em>  while(lent1 <= 0 || lent1 > 50){</em>

<em>      System.out.print("Length of array 1: ");</em>

<em>      lent1 = input.nextInt();  }</em>

This declares the first array

 int[] array1 = new int[lent1];

This prompts the user for length of the second array

 System.out.print("Length of array 2: ");

This declares and gets input for the length of the second array

 int lent2 = input.nextInt();

This validates the length of the second array

<em>  while(lent2 <= 0 || lent2 > 50){</em>

<em>      System.out.print("Length of array 2: ");</em>

<em>      lent2 = input.nextInt();  }</em>

This declares the second array

 int[] array2 = new int[lent2];

The following generates random integers between 1 and lent1*2 to array 1

<em>  for(int i =0;i<lent1;i++){</em>

<em>      array1[i] = (int)(Math.random() * (lent1*2) + 1);  }</em>

The following generates random integers between 1 and lent2*2 to array 2

<em>  for(int i =0;i<lent2;i++){</em>

<em>      array2[i] = (int)(Math.random() * (lent2*2) + 1);  }</em>

This prints the header Array 1

 System.out.print("Array 1: ");

The following iteration prints the content of the first array

<em> for(int i =0;i<lent1;i++){</em>

<em>      System.out.print(array1[i]+" ");</em>

<em>  }</em>

This prints the header Array 2

 System.out.println("Array 2: ");

The following iteration prints the content of the second array

<em>  for(int i =0;i<lent2;i++){</em>

<em>      System.out.print(array2[i]+" ");</em>

<em>  }</em>

<em />

You might be interested in
Select the correct answer from each drop-down menu.
Gelneren [198K]

Answer:

Maybe computer engineering and marketing skills

4 0
3 years ago
How to jail break iphone 7 with <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7617023602">[email&#160
GarryVolchara [31]
I do not think so i honestly do not know
6 0
3 years ago
Read 2 more answers
software that instructs the computer how to run applications and controls the display/keyboard is known as the
OverLord2011 [107]
<span>Operating System is the software that gives the computer instructions on how to run applications. It is considered the most important program that runs on a computer because it manages all the hardware and software on it. It also controls the display/keyboard. </span>
4 0
3 years ago
A communication medium which allows receivers to observe multiple cues, such as body language and tone of voice, and allows send
castortr0y [4]

Answer: Rich medium

Explanation: A communication is said to be rich id it provides the services like observing the body language, immediate communication, instant judging of the voice tone etc. These factors are commonly found in the face to face interaction which is considered as the rich source of communication. It is considered as rich medium because  it has the capability of receiving the output immediately .

4 0
3 years ago
Can anybody answer this
shutvik [7]

Answer:

Its the last one, CSS and HTML are similar but like it says some prefer one over the other.

6 0
3 years ago
Read 2 more answers
Other questions:
  • What role do career pathways play?
    11·2 answers
  • Program should allow for user to enter students name and his four test scores it should calculate and display the average and le
    7·1 answer
  • AddAll - Adds all the doubles in the string with each other. Note every double is separated by a semi-colon. AddAll("1.245;2.9")
    6·1 answer
  • What is the quickest way to change the format of a table?
    8·1 answer
  • Similarly, the Windows server OS can run regular workstation applications such as MS Office or Adobe Photoshop. Why is this a ba
    5·1 answer
  • What happens if none of the selector values match selector in a simple case expression in pl/sql
    6·1 answer
  • When would you insert a merge field?
    10·2 answers
  • Create a query that shows columns employee last name, job title and hire date for those employees who joined the company on or a
    7·1 answer
  • You are a network administrator for your company. The network consists of a single Active Directory domain. All servers run Wind
    7·1 answer
  • Which of the following expressions in Java is equal to 4?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!