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]
2 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]2 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
True or False? At any point in time, an open file has a current file pointer indicating the place where the next read or write o
mr_godi [17]

Answer:

True is the correct answer for the above question.

Explanation:

  • When any document file is opened then every point has some particular address. so there is a pointer which states that where the read operation and the write operation is going on.
  • When any person writes any program to read a file or write a file then there is a need for some variable that is pointed for the reading and the write operation.
  • The document which is used for the write data or read data is also designed and maintained by some software.
  • Hence we can say that there are needs of some variable that point the operation of the file and it is also stated from the above question. Hence the above question statement is a true statement.
5 0
3 years ago
What is a location where the embedded multimedia terminal is connected to both outside and inside wiring​
anygoal [31]

Answer:

The answer to this question is "The main closet or telecommunications closet".

Explanation:

A multimedia terminal or multimedia terminal adapter (MTA) is also known as a Landline modem that operates just like a wireless router, but in terms of high-speed Internet, an MTA can provide Home Phone service only.

  • In the case of a significant power failure, MTAs have only a backup battery that will fuel the MTA for many hours.
  • This device is used to connect to a main or telecommunications closet.

4 0
3 years ago
When a router forwards incoming packets closer to their destination hosts, this is called?
il63 [147K]
Port forwarding, I think.
3 0
3 years ago
By what decade were books readily available to the public across the United States and Europe? A. 1690 B. 1750 C. 1860 D. 1820
sladkih [1.3K]

Answer: 1820

Explanation:

I <u>believe</u> the answer is the 1820, as the introduction of steam powered printing presses and steam powered paper mills significantly lowered the cost of books to decrease and significantly increased their circulation/availability.

hope this  helps

-lvr

6 0
3 years ago
What is the easiest way to create a diverse set of cover pages?<br><br> Word 2016
Sindrei [870]

Answer:

using the cover page gallery

Explanation:

This is certainly the easiest way. And you just need to add this as first page, set the borders, pagination, headers and footers from second page, and avoiding the first page as it is the cover page as well as customize the various section of the cover page design you choose.

Inserting a blank page will require a lot of effort.

Inserting pictures will not  result into a complete and a meaningful cover page.

Same is the case if you insert shapes.

hope it helps :)

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which statement describes the word "iterative"?
    7·2 answers
  • In the SQL environment, a _____________ is a logical group of database objects – such as tables and indexes – that are related t
    11·1 answer
  • This exspansion slot essentially replaced PCI and AGP slots
    14·1 answer
  • What in the LAN for a small office, some user devices connect to the LAN using a cable, while others connect using wireless tech
    14·1 answer
  • You have a small network at home that is connected to the internet. On your home network, you have a server with the IP address
    11·1 answer
  • What are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
    8·1 answer
  • What will be the results from running the following code?
    5·1 answer
  • what social media application that affect our day to day activities, and how did it improve our skill
    9·1 answer
  • Develop a C program that calculates the final score and the average score for a student from his/her (1)class participation, (2)
    9·1 answer
  • write query for all products reutrn product name with its amounts due, paid, canceled, and refunded, order the result by product
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!