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
1) Create a recursive program that prompts the user for a nonnegative integer N and outputs. a) Sum [N] b) BiPower [N] c) TimesF
Georgia [21]

Answer:

//Code is created using java

import java.util.*;

// returns the sum

public int sum(int N)

{

if(N==1)

return (1);

else

return N+sum(N-1);

}

// code to return the Bipower ouput

public int BiPower(int N)

{

if(N==1)

return (2);

else

return 2*BiPower(N-1);

}

// Code to return TimesFive output

public int TimesFive(int N)

{

if(N==1)

return 5;

else

return 5 + timesFive(N-1);

}

public static void main(String args[])

   {

//Prompts the user to enter a nonnegative integer

       int N  = Integer.parseInt.(console.readLine("Enter a nonnegative integer:  "));

//Outputs the sum, Bipower and TimesFive

       System.out.println(sum(n));

       System.out.println(BiPower(n));  

       System.out.println(TimesFive(n));

   }

}

4 0
3 years ago
________ refers to the ability to model components and show how the components' inputs and outputs relate to one another.
Black_prince [1.1K]

Answer:

Central Processing Unit

Explanation:

When the CPU puts the address of a peripheral onto the address bus, the input–output interface decodes the address and identifies the unique computer peripheral with which a data transfer operation is to be executed.

5 0
3 years ago
Which of the following are some popular debugging techniques?
topjm [15]

Answer:

a fix any syntax bugs. I looked it up on the internet so you should be good good luck on your test

8 0
2 years ago
Berikan contoh perameter sebuah meja.​
lara31 [8.8K]

Answer:

The simplest of table parameters are rows, columns, page number, alternate row, column header, Table title, etc.

Explanation:

The simplest table parameter is as being mentioned above. Its, however, important to understand what are the parameters. Parameters are the features of an object that defines its behavior. Various parameters are the behaviors of the object hence, and here it is the table and the behavior of the table is being described with the parameters. There are so many other parameters that one can think of related to tables. And we should make a list of them for future studies. Font size, Font color, border, etc are some more from the huge list.

5 0
3 years ago
In computer science, what does the word security mean?
zepelin [54]

Answer:

B

Explanation:

Computer security, cybersecurity or information technology security (IT security) is the protection of computer systems and networks from information disclosure, theft of or damage to their hardware, software, or electronic data, as well as from the disruption or misdirection of the services they provide.[1]

4 0
3 years ago
Other questions:
  • Write the execution steps if the input is a lion.
    11·1 answer
  • Plz help meeeeee QUICKLY!!! WORTH 15 POINTS!
    15·1 answer
  • How would you copy all files from a remote directory into your LOCAL home folder.
    6·1 answer
  • . Describe a way to simplify a complex problem.
    8·1 answer
  • You have just finished installing a network adapter adapter and booted up the system, the drivers. You open File Explorer on a r
    13·1 answer
  • Miguel owns a tile business. He has two employees who work in a small office. One answers phones and schedules appointments. Ano
    11·2 answers
  • Microsoft Excel is an example of a(n) application.
    11·2 answers
  • Which components are involved with input? Output? Processing? Storage?
    15·2 answers
  • On the MarketingConsultants worksheet, in cells D10:H13, use a PMT function to calculate the end of the month payment amount. En
    15·1 answer
  • Identify 5 internal and external hardware components of a server
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!