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
In the microsoft powerpoint view tab, which presentation view enables a user to view one slide at a time in the slide pane? a no
fredd [130]
Normal is the correct answer
6 0
3 years ago
What makes a computer a computer?​
BabaBlast [244]

Answer:

A computer is an electronic device that manipulates information, or data. It has the ability to store, retrieve, and process data. You may already know that you can use a computer to type documents, send email, play games, and browse the Web

Explanation:

Follow me..............

8 0
3 years ago
Read 2 more answers
Set the following for loop header so that it prints the numbers, 0 2 4 6 8.
olya-2409 [2.1K]
Option D is correct. The loop should look like this:

for (int i = 0; i < 10; i += 2)
{
     System.out.print(i + " ");
}
5 0
3 years ago
Read 2 more answers
Who knows how to get unbanned from brainly?
babunello [35]

Answer:

no way

Explanation:

but you can make unlimited accounts and bre.ak the sever

ps for the em.ail just put somethingatgm.ail.com

8 0
2 years ago
Read 2 more answers
Michael has increased the contrast of the given picture. Which feature or menu option of a word processing program did he use?
shepuryov [24]

ANSWER

A. Format  

Hope this helps!!!

8 0
4 years ago
Read 2 more answers
Other questions:
  • What are the minimum pixel dimensions of a monitor?
    11·1 answer
  • A subclass of Value, LargerValue, is defined with a getValue method that returns twice the value of the parent. Which line is th
    13·1 answer
  • Typically , how do people earn income
    11·2 answers
  • What practices will help you avoid sending out e-mail to the wrong person?
    15·1 answer
  • Which online resource is usually not free?
    10·2 answers
  • Which of the following is an absolute cell reference
    10·1 answer
  • Cloud computing is an old phenomenon in computing infrastructure dating back to the early days of the Internet that involves mov
    10·1 answer
  • Recall that within our BinarySearchTree class the root variable is of type BSTNode. A BSTNode object has three attributes: info
    13·1 answer
  • is a measurement that quantifies how much information can be transmitted over the network. A. Memory B. DMZ C. Bandwidth D. Clou
    10·1 answer
  • Can anyone answer this ​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!