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
KonstantinChe [14]
3 years ago
10

Write a Java program that has a static method named range that takes an array of integers as a parameter and returns the range o

f values contained in the array. The range of an array is defined to be one more than the difference between its largest and smallest element. For example, if the largest element in the array is 15 and the smallest is 4, the range is 12. If the largest and smallest values are the same, the range is 1.
Computers and Technology
1 answer:
SashulF [63]3 years ago
5 0

Answer:

The program in Java is as follows:

import java.util.*;

import java.lang.Math;

public class Main{

public static int range(int low, int high){

    return Math.abs(high - low)+1;

}

public static void main(String[] args) {

 Scanner scnr = new Scanner(System.in);

 int num1 , num2;

 System.out.print("Enter two numbers: ");

 num1 = scnr.nextInt();

 num2 = scnr.nextInt();

 System.out.print(range(num1,num2));

}

}

Explanation:

This defines the range method

public static int range(int low, int high){

This calculates and returns the range of the two numbers

    return Math.abs(high - low)+1;

}

The main begins here

public static void main(String[] args) {

 Scanner scnr = new Scanner(System.in);

This declares 2 numbers as integer

 int num1 , num2;

This prompt the user for two numbers

 System.out.print("Enter two numbers: ");

The next two lines get input for the two numbers

 num1 = scnr.nextInt();

 num2 = scnr.nextInt();

This calls the range function and prints the returned value

 System.out.print(range(num1,num2));

}

You might be interested in
Explain in detail what it means to synchronize computers and mobile devices. include at least two strategies for keeping your fi
alexdok [17]
Keeping track of common files by using a lot of computers and mobiles all through the day may be hard. A good example is when you synchronized your mobile and computer devices. If you check an email using your computer, it will also appear in your smartphone. This will be a lot easier to track your email through both of your devices than having not to be synced at all.
8 0
3 years ago
Two electronics students are discussing electrical units. Student A says that electrical power is measured in units called coulo
MakcuM [25]

watts is the measurement for electrical power

V is abbreviation for volts


 Answer is A Neither of the two students is correct

6 0
3 years ago
For the Address Block 195.200.0.0/16 a. If you have 320 Customers that need 128 addresses/customer - will there be enough addres
Shkiper50 [21]

Answer / Explanation:

195.200.0.0/16

Note: Class C address can not be assigned a subnet mask of /16 because class c address has 24 bits assigned for network part.

2ⁿ = number of subnets

where n is additional bits borrowed from the host portion.

2ˣ - 2 = number of hosts

where x represent bits for the host portion.

Assuming we have 195.200.0.0/25

In the last octet, we have one bit for the network

number of subnets  = 2¹  =2 network addresses  

number of host = 2⁷ - 2= 126 network addresses per subnets

8 0
3 years ago
C++
vichka [17]

Answer:

#include <iostream>

#include <map>  

using namespace std;

int main()

{

   map<int, int> numbers;

   cout << "Enter numbers, 0 to finish" << endl;

   int number;

   while (true) {

       cin >> number;

       if (number == 0) break;

       numbers[number]++;

   }

   for (pair<int, int> element : numbers) {

       std::cout << element.first << ": occurs " << element.second << " times" << std::endl;

   }

}

Explanation:

One trick used here is not to keep track of the numbers themselves (since that is not a requirement), but start counting their occurrances right away. An STL map< > is a more suitable construct than a vector< >.

4 0
3 years ago
The letters a, e, i, o and u are the only vowels. Write a function named vowelUseDict() takes a string t as a parameter and comp
Andru [333]

Please specify the programming language.


3 0
3 years ago
Other questions:
  • CAD helps professionals to _____. create a technical drawing give directions to a new location calculate the interest rate of a
    13·2 answers
  • Suppose two hosts, A and B, are separated by 15,000 kilometers and are connected by a direct link of R = 5 Mbps. Suppose the pro
    11·1 answer
  • Within the Chart Design tab, which section is used to change the data of a previously created chart?
    12·1 answer
  • Prewritten, commercially available sets of software programs that eliminate the need for a firm to write its own software progra
    7·1 answer
  • Explain the main components of a computer system​
    12·1 answer
  • What is the second step when designing an algorithm?
    12·2 answers
  • Which of the following techniques is a direct benefit of using Design Patterns? Please choose all that apply Design patterns hel
    12·1 answer
  • A character that <br>is raised and smaller above the baseline is called​
    6·1 answer
  • What is the main function of the output on a computer or what is it use for? ​
    15·2 answers
  • Ten ways ict has helped in social development
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!