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
4 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]4 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
if you are trying to reduce your debt, which of these expenses should you consider cutting out or cutting back on first?
Ainat [17]
Pay off highest interest rates first

cut back on un needed expenses-coffee, itunes etc


8 0
4 years ago
How can templates be made available to other users?
Daniel [21]

Answer:

b

Explanation:

4 0
3 years ago
I have a question, but it's not a math question. Can anyone give me 5 unblockers for school computers? If you answer this, you w
ValentinkaMS [17]

Answer:

I mean if your talking about games then just try Cool math I will give link in comments

Explanation:

4 0
2 years ago
Read 2 more answers
En que parte del mall del rio venden tarjetas de google play en cuenca​
JulijaS [17]

chxgfk hcyskvuct auhchovuzq vuvscisv

6 0
3 years ago
A) Explain the concept of memory management unit as related to Operating systems.
USPshnik [31]

Answer:

Memory is the faculty of the brain by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action.

Explanation:

4 0
3 years ago
Other questions:
  • Fill in the blanks.
    6·2 answers
  • When you first launch the internet, what page will open?
    9·1 answer
  • Nascar has inserted an image into his document but needs the image to appear on its own line Which option should he choose?
    12·2 answers
  • The idea that managers tend to communicate more with other managers who share similar beliefs and experiences is represented by
    8·1 answer
  • What would be the state of the following list after each of the first four passes in a Bubble sort, sorting into ascending seque
    15·2 answers
  • 5. How many subnets are possible in a network with a /19 CIDR?
    5·1 answer
  • Which code will allow Jean to print Coding rocks! on the screen?
    6·1 answer
  • Input a list of positive numbers, terminated by 0, into an array Numbers[]. Then display the array and the largest and smallest
    11·1 answer
  • What are ways to create a study schedule? Check all that apply.
    5·2 answers
  • Which is the fastest memory in computer​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!