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]
2 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]2 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
Consider the following recursive method: public int someFun(int n) { if (n <= 0) return 2; else return someFun(n-1) * someFun
Stella [2.4K]

Answer:

(a) someFunc(3) will be called 4 times.

(b) For non negative number n someFunc method calculates 2^2^n.

Explanation:

When you call someFunc(5) it will call someFunc(4) two time.

So now we have two someFunc(4) now each someFunc(4) will call someFunc(3) two times.Hence the call to someFun(3) is 4 times.

someFunc(n) calculates someFunc(n-1) two times and calculates it's product.

someFunc(n) = someFunc(n-1)^2..........(1)

someFunc(n-1)=someFunc(n-2)^2..........(2)

substituting the value form eq2 to eq 1.

someFunc(n)=someFunc(n-2)^2^2

       .

       .

       .

       .

= someFunc(n-n)^2^n.

=2^2^n

2 raised to the power 2 raised to the power n.

3 0
3 years ago
The router can deliver packets directly over interfaces 0 and 1 or it can forward packets to Routers R2, R3, or R4. Describe wha
ra1l [238]

Answer:

Following are the solution to this question:

Explanation:

In point A:

It applies the AND operation with the subnet-mask that is  

=128.96.39.00001010 \ \ AND \ \ 255.255.255.10000000 \\\\= 128.96.39.0000000 \\\\= 128.96.39.0 \\\

This corresponds to a 128.96.39.0 subnet. This is why the router sent the packet to 0.

In point B:  

It applies the AND operation with the subnet-mask that is 255.255.255.128

= 128.96.40.00001100\  AND \ 255.255.255.10000000 \\\\ = 128.96.40.0000000\\\\= 128.96.40.0

This suits the 128.96.40.0 subnet. The router then sent R2 to the packet. The packet.

In point C:  

It  applies the AND operation with the subnet-mask that is 255.255.255.128

=128.96.40.10010111 \ AND \ 255.255.255.10000000 \\\\= 128.96.40.1000000\\\\= 128.96.40.128

It  applies the AND operation with the subnet-mask  that is 255.255.255.192

= 128.96.40.10010111 \ AND \ 255.255.255.11000000 \\\\= 128.96.40.1000000 \\\\= 128.96.40.128\\

All of the matches of its sublinks above.  

Its default R4 router was therefore sent to the router by router.

In point D:

It  applies the AND operation with the subnet-mask  that is 255.255.255.192

= 192.4.153.00010001 \ AND \ 255.255.255.11000000\\\\ = 192.4.153.0000000 \\\\= 192.4.153.0 \\\\

It matches the 192.4.153.0 subnet. It router has sent packet to R3 then.

In point E:

It  applies the AND operation with the subnet-mask  that is 255.255.255.128

= 192.4.153.01011010\  AND \ 255.255.255.10000000 \\\\= 192.4.153.0000000 \\\\= 192.4.153.0

There, neither of the subnet inputs correlate with the ip address with the same subnet mask.

It  applies the AND operation with the subnet-mask  that is 255.255.255.192

=192.4.153.01011010\ AND \ 255.255.255.11000000 \\\\ = 192.4.153.0100000 \\\\= 192.4.153.64

It does not correlate to the subnet entries for same subnet mask, and therefore neither of the entries matches their corresponding ip address entries.  

Mask of the subnet.  That packet would therefore be sent to the default R4 router by the router.

4 0
2 years ago
Which of the following will you do in step X in the following series of clicks to change the bounds of
ser-zykov [4K]

In order to change the bounds of  a chart axis after performing the aforementioned series of clicks, at step X: C. Type the number that you want in the text box.

A step chart can be defined as a line chart that uses both the vertical and horizontal lines to connect two (2) data points. Thus, it enables an end user to see the exact point on the X-axis when there is a change in the Y-axis.

In Microsoft Excel, the series of clicks that are used to change the bounds of  a chart axis are:

  • Click on chart.
  • Select chart tools and then format tab.
  • Select the current selection and then format selection.
  • Click on format axis and then axis options.
  • Click on vertical axis crosses.
  • At category number, you should type the number that you want in the text box.

In conclusion, typing the number that you want in the text box is the action that should be performed at step X.

Read more on step chart here: brainly.com/question/9737411

3 0
2 years ago
What are the Difference between turbo C++ and Java programing?
slavikrds [6]

**Difference between Turbo C++ and Dev C++

Answer:

1. Turbo C++ (TC) :

It is a compiling software used for C and CPP Language. The initial release was in May 1990 but the first stable version released in September 2008. It takes more memory and time to load as compared to Dev C++. Turbo C++ is the compiler from which most of us start our coding life in school/college.

2. Dev C++ :

Dev C++ is also used for C and CPP Language. The first stable release was in April 2015. It is fast as compared to Turbo C++. Dev C++ is very much similar to Online Compilers which we used in Coding Competitions.

8 0
2 years ago
Which would be the best user error message?A) Invalid parameterB) You must type a user name to continue.C) enter a user name to
brilliants [131]

Answer:

The best user error message would be C in my opinion

Explanation:

It does not directly engage with the user and instead simply states the course of action needed which allows users to know what needs to be done without being overly detailed in instructions in Option E or overly engaged or informal.

6 0
3 years ago
Other questions:
  • What happens if you move unencrypted files into an encrypted folder?
    5·1 answer
  • CNG and gasoline-powered vehicles use the same internal combustion engine, but different fuel types. A) True B) False
    8·2 answers
  • Boolean expressions are named after ____
    9·1 answer
  • Which of the following are examples of how a company might use consumer data it had collected? a To decide what types of product
    10·1 answer
  • Who was the founder of the location-sharing site Whrrl
    6·1 answer
  • For the recursive method below, list the base case and the recursive statement, then show your work for solving a call to the re
    8·1 answer
  • True or False: Nested elements must be indented with respect to parent elements in
    13·1 answer
  • Which is NOT something that a game producer needs to do?
    14·1 answer
  • What is the purpose of a format painter in Word?
    15·2 answers
  • I need a solution for this problem asap.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!