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
Crank
3 years ago
6

Write a method called printRange that accepts two integers as arguments and prints the sequence of numbers between the two argum

ents, separated by spaces. Print an increasing sequence if the first argument is smaller than the second; otherwise, print a decreasing sequence. If the two numbers are the same, that number should be printed by itself. Here are some sample calls to printRange:printRange(2, 7);printRange(19, 11);printRange(5, 5);The output produced from these calls should be the following sequences of numbers:2 3 4 5 6 719 18 17 16 15 14 13 12 115Test the method using the following main program:import java.util.*; // for Scannerpublic class Lab4Q2 {public static void main(String[] args) {Scanner console = new Scanner(System.in);System.out.print("Enter a positive integer: ");int num1 = console.nextInt();System.out.print("\nEnter a second positive integer: ");int num2 = console.nextInt();System.out.println();printRange(num1, num2);}
Computers and Technology
1 answer:
Papessa [141]3 years ago
4 0

Answer:

import java.util.*;

// for Scanner

public class Lab4Q2{

     public static void main(String[] args){

           Scanner console = new Scanner(System.in);

           System.out.print("Enter a positive integer: ");

           int num1 = console.nextInt();

           System.out.print("\nEnter a second positive integer: ");

           int num2 = console.nextInt();

          System.out.println();

          printRange(num1, num2);

}

     public static void printRange(int a, int b){

           if(a == b){

               System.out.print(a);

}           else if (a < b){

                for(int i = a; i <= b; i++){

                     System.out.print(i + " ");

}

}

           else if (a > b){

                for(int i = a; i >= b; i--){

                    System.out.print(i + " ");

}

}

}

}

Explanation:

In the printRange method that is called from the main method; we pass the two parameters of numbers entered as 'a' and 'b'. First, we check if 'a' and 'b' are the same, then we output a single instance of the input.

Next, we check if the first input is less than the second input then we output in ascending order.

Lastly, we check if the first input is greater than the second input then we output in descending order.

You might be interested in
The following is a training dataset that has ten one dimensional objects.
grandymaker [24]
Yes no no false . . . .
6 0
2 years ago
Var amount = 100;
IRISSAK [1]

Answer:

0.1

Explanation:

The value of amount is 100.So in the if-else-if ladder first condition in if will be checked since the amount is greater than 50 so the value of discount will become 0.1 and the execution of if else if ladder will be finish.The compiler will not be executing elseif or else.So the answer to this question is 0.1.

4 0
3 years ago
What would you use to see what network adapters are installed in your windows computer?
Lesechka [4]
I wouldn't see anything, because my computer does not use any network adaptors.
6 0
2 years ago
_____ is a group of Internet-based applications that build on the ideological and technological foundations of Web 2.0, and that
lutik1710 [3]

Answer: Social media

Explanation:

 Social media is defined as the group of the internet based various applications that basically build on the foundation of  technological and ideological of the web 2.0. It basically allow the exchange of the user content and creation.

It is the most flexible platform that enable the users with the huge experience. It is also known as free and open source platform. It basically contain the various content that are algorithm driven and machine learning.

 

3 0
2 years ago
There are many different types of hardware devices, different manufacturers, and countless configuration possibilities. Explain
erik [133]

Because, they are all required to configure to it to be recognized by an operating system.

Explanation:

It is the Operating System Software that instructs the hardware and puts them together to work well. When the manufacturer does not configure the device to be recognized by an operating system, then it will not work with other components.

Example.

If an Apple machine's sound card is being put in an HP machine which uses Microsoft designed operating system, won't work due to the operating system that the sound card has been designed for.

6 0
3 years ago
Other questions:
  • What is the purpose of a scatter plot introduction to computer applications
    6·2 answers
  • What option is available on a Host A record to tell the system how long the record should remain in the database after it was cr
    15·1 answer
  • What is the correct order of headers, from left to right, in a completed frame?
    8·1 answer
  • Items that are cut or copied are placed on the Clipboard.
    6·2 answers
  • What type of coverage pays for damage incurred as a result of theft, vandalism, fire or natural disaster?
    15·1 answer
  • What component uses thermal paste to attach the heat sink?
    13·1 answer
  • A small company with 100 computers has hired you to install a local area network. All of the users perform functions like email,
    9·1 answer
  • What profession do you prefer to have in the future? In what way could you make an impact on society using the Internet?
    7·1 answer
  • Write a C# program named ProjectedRaises that includes a named constant representing next year’s anticipated 4 percent raise for
    15·1 answer
  • What free website can you record videos on, and edit them without money?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!