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
Distinguish<br> between formal and Informal<br> Information System<br> Information systems
Harlamova29_29 [7]

Explanation:

Formal; A formal information system is based on

the organization represented by the organization chart.

Informal; The informal information system is

employee based system designed

to meet personal and vocational needs

and to help in solution of work-related problems.

5 0
2 years ago
A user wants to quickly share pictures between mobile devices. The devices will be in close proximity so the necessity of a thir
BlackZzzverrR [31]

Answer:

NFC(Near Field Communication).

Explanation:

When user wants to share pictures quickly between the mobile devices which are in very close proximity we can use NFC(Near Field Communication).

Near Field Communication(NFC):-It is a group of communication protocols that lets two devices most of the times these are mobile phones to establish connection and the distance between them should be less around 4 centi meter.

8 0
3 years ago
____ gets its name from the notion that it ignores the traditional A, B, and C class designations for IP addresses and can there
Sedbober [7]

<u>Classless Inter-Domain Routing</u> gets its name from the notion that it ignores the traditional A, B, and C class designations for IP addresses and can therefore set the network-host ID boundary wherever it wants to, in a way that simplifies routing across the resulting IP address spaces.

<u>Explanation</u>:

A router is a networking device that helps in connecting multiple networks. <em><u>Classless Inter-Domain Routing (CIDR) </u></em>is used for creating IP addresses and IP routing. CIDR was introduced in the year 1993 by <em><u>“The Internet Engineering Task Force”</u></em>. The classful network design was replaced by CIDR in the Internet.

The IP addresses are responsible for sending the particular information packets to specific computers. Classless inter-domain routing helps in improving the allocation of IP addresses.

7 0
3 years ago
Read 2 more answers
When you ask the database more complex questions using comparison operators, you are conducting a _____?
yulyashka [42]
<span>When you ask the database more complex questions using comparison operators, you are conducting a query.
</span><span>The term "query" denotes  a programmatic statement that is understand by a the DBMS(Database management system) that understands how to access and manipulate data within a database. </span>
7 0
3 years ago
Read 2 more answers
A business owner whishes to know which clients are the highest paying clients of his business. What tool is he likely to use to
Zolol [24]

Answer:

The answer is "Sorting".

Explanation:

Throughout this statement, the owner needs to understand which one of its customers pays the greatest wage so the best method is sorting that handles the data easily.

This method provided an amount of data that could be organized or sort in an attempt to discover the lowest as well as other supplementary information, either an increase or decrease, easily or easy to understand, is named sorting.

8 0
2 years ago
Other questions:
  • 3k means about 3 thousand bytes. how would you express two hundred million bytes?
    8·1 answer
  • 2. Add a _______ to manually force text from one page to the next page. A. footer B. page break C. blank page D. header
    11·2 answers
  • Conduct online research to determine specific conflict-resolution and management techniques and skills that would be beneficial
    5·1 answer
  • Provide the instruction type, assembly language instruction, and binary representation of instruction described by the following
    7·1 answer
  • 1. Explain the distinction between interpretation and compilation. What are the comparative advantages and disadvantages of the
    13·1 answer
  • Router 1 is configured with static NAT. Addressing on the router and the web server are correctly configured, but there is no co
    11·1 answer
  • What would happen if computers only had input devices?
    9·1 answer
  • Explain the term information security?​
    9·1 answer
  • Helppppppppppppppp me please Can i have help for a ggogle class room
    5·1 answer
  • What enables image processing, speech recognition, and complex game play in artificial intelligence?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!