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
Define a function in Scheme (or relation in Prolog) that checks whether a set of elements (represented as a list) is a subset of
mafiozo [28]

Answer:

subset([],[]).

       subset([X|L],[X|S]) :-

           subset(L,S).

       subset(L, [_|S]) :-

           subset(L,S).

Success:

     subset([1,3], [1,2,3]).

     subset(X, [1,3,4]).        % error handling to compare sets in a given order

Fail:

     subset([2,1], [1,2,3]).   % compares in a different order from the first.

Explanation:

The function "Subset" in the source code above accepts two sets, then checks if the first set is a subset of the second. The code returns true if the condition is met.

4 0
3 years ago
When determining the cost of an item, the seller will often analyze the demand as well as the supply before setting the price of
juin [17]

Answer:

The price of a commodity is determined by supply and demand. therefore the answer is COMMODITY. that other person is wrong

7 0
3 years ago
Which of these statements describes the difference between binary and decimal numbers?
ElenaW [278]

Answer:

A

Binary numbers use only the digits 0 and 1; decimal numbers use 0 through 9.

Explanation:

Binary means in couples of two. So you count using 0s and 1s like 01, 10, 11, 100, 101, 110, 111, and so on.

7 0
3 years ago
Read 2 more answers
What is the difference between asking a question with few points and asking a question with many? New to Brainly :D
ANTONII [103]

Answer:

one would be more helpful and the other more vague and less convincing.

6 0
3 years ago
To what competitive force did the printed encyclopedia industry succumb? 1. Substitute products or services 2. Increased bargain
Nikolay [14]

Answer:

Option 1 i.e., Substitute products or services.

Explanation:

The printed encyclopedia industrial sector lost to the economic power of replacing goods or services.

In the industrial countries, the current economic situation is not feasible in terms of its consumption of products as per capita. The ' service economy ' applies not only for the tertiary sector but for an economy in which businesses generate the balance of income, and most workers are also in service operations.

7 0
4 years ago
Other questions:
  • What kind of device should you install if you need the device to perform network address translation, facilitate access to the I
    6·1 answer
  • In which of the following scenarios would it be best to use a for loop?
    6·1 answer
  • What does phishing mean?
    9·2 answers
  • Suppose Alice, Bob, and Carol want to use secret key technology to authenticate each other. If they all used the same secret key
    10·1 answer
  • Betty removed a web page from her website. Some users were browsing on her website. One of them clicked on a particular link and
    10·1 answer
  • Write a function that, given an array A of N integers, of which represents loads caused by successive processes, the function sh
    15·1 answer
  • Which of these statements about symmetric key encryption is true? The file is encrypted with a private key and can be decrypted
    14·1 answer
  • A keyboard shortcut to pasting in a document is to key _____.
    8·1 answer
  • What describes the current cloud landscape for business?
    12·1 answer
  • A pcr-based method to detect a specific pathogen in a specimen works by amplifying a ________ that is specific to the prospected
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!