answer.
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
max2010maxim
2 months ago
8

Number pattern Write a recursive method called print Pattern() to output the following number pattern. Given a positive integer

as input (Ex: 12), subtract another positive integer (Ex: 3) continually until 0 or a negative value is reached, and then continually add the second integer until the first integer is again reached.

Engineering
2 answers:
mote1985 [299]2 months ago
4 0

Response:

import java.util.Scanner;

public class NumberPattern {  

public static void decrement(int num1, int num2)

{

   if(num1 < 0)

    return;

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

   decrement(num1 - num2, num2);

}

public static void increment(int num1, int num2)

{

int current = num1 - ((num1 / num2) * num2);

current = current + num2;

begin(num1, num2, current);

}

public static void begin(int num1, int num2, int current)

{

    if(current > num1)

     return;

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

    begin(num1, num2, current + num2);

}

public static void displayNumPattern(int num1, int num2)

{

  decrement(num1, num2);

  increment(num1, num2);

}

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int num1;

int num2;

num1 = scnr.nextInt();

num2 = scnr.nextInt();

displayNumPattern(num1, num2);

}

}

Clarification:

alex41 [359]2 months ago
3 0

Response:

Refer to the explanation

Clarification:

Code:

import java.util.Scanner;

public class NumberPattern {

public static int x, count;

public static void displayNumPattern(int num1, int num2) {

if (num1 > 0 && x == 0) {

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

count++;

displayNumPattern(num1 - num2, num2);

} else {

x = 1;

if (count >= 0) {

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

count--;

if (count < 0) {

System.exit(0);

}

displayNumPattern(num1 + num2, num2);

}

}

}

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int num1;

int num2;

num1 = scnr.nextInt();

num2 = scnr.nextInt();

displayNumPattern(num1, num2);

}

}

See attached example output

You might be interested in
A technician has been dispatched to assist a sales person who cannot get his laptop to display through a projector. The technici
mote1985 [299]

Answer:Ensure the correct cable is connected between the laptop and the projector. Check for HDMI inputs or 15-pin video output interfaces.

Also, make sure the laptop is set to project to the correct display output.

Explanation:

7 0
2 months ago
Design a digital integrator using the impulse invariance method. Find and give a rough sketch of the amplitude response, and com
mote1985 [299]
50 μsec.
8 0
1 month ago
A 227 pound compressor is supported by four legs that contact the floor of a machine shop. At the bottom of each leg there is a
choli [298]

Answer:

1.312 in

Explanation:

The details provided in the question are:

The weight of the compressor, W is 227 pounds.

It has 4 legs.

The maximum permissible pressure is 42 psi.

Let F represent the force exerted by each leg.

Thus,

W = 4F,

or

227 pounds = 4F,

implying that:

F = 56.75 pounds.

Furthermore,

Force = Pressure × Area,

therefore:

56.75 pounds = 42 psi × πr²  [ r signifies the radius of one leg]

Consequently, we find:

r² = 0.4301,

and thus:

r = 0.656;

resulting in a diameter equal to 2r = 2 × 0.656,

which equals 1.312 in.

6 0
2 months ago
A 90-hp (shaft output) electric car is powered by an electric motor mounted in the engine compartment. If the motor has an avera
pantera1 [306]

Answer:

Heat supply rate is measured at 8.901 horsepower.

Explanation:

Energy efficiency of the electric vehicle, as per Thermodynamics (\eta), is the proportion of translational mechanical power (\dot E_{out}), expressed in horsepower, and electrical energy (\dot E_{in}), also in horsepower. The heat supply rate (\dot E_{l}), indicated in horsepower, that the motor delivers to the engine bay under full load can be determined by subtracting the translational mechanical energy from the electric energy. This is expressed as:

\eta = \frac{\dot E_{out}}{\dot E_{in}} (1)

\dot E_{l} = \dot E_{in}-\dot E_{out} (2)

\dot E_{l} = \left(\frac{1}{\eta}-1\right)\cdot \dot E_{out} (3)

If we have the values of \eta = 0.91 and \dot E_{out} = 90\,hp, the heat supply rate can be calculated as:

\dot E_{l} = \left(\frac{1}{0.91}-1 \right)\cdot (90\,hp)

\dot E_{l} = 8.901\,hp

The heat supply rate amounts to 8.901 horsepower.

4 0
2 months ago
___________ is NOT a common injury that an automotive tech may experience at work.
Viktor [391]

Answer: The most frequently occurring injuries were sprains/strains, accounting for 39% of the total; lacerations comprised 22%, and contusions represented 15%. Almost half (49%) of the injuries led to one or more days of lost or restricted work; 25% resulted in 7 or more days lost or restricted.

Explanation:

Sprains/strains were the predominant injuries happening, making up 39% of all cases, while lacerations followed at 22% and contusions at 15%. Of these injuries, 49% caused employees to miss or face restricted workdays, with 25% leading to a minimum of 7 days lost or restricted.

7 0
3 months ago
Other questions:
  • 3.24 Program: Drawing a half arrow (Java) This program outputs a downwards facing arrow composed of a rectangle and a right tria
    12·1 answer
  • Water is flowing in a metal pipe. The pipe OD (outside diameter) is 61 cm. The pipe length is 120 m. The pipe wall thickness is
    9·1 answer
  • 5 kg of steam contained within a piston-cylinder assembly undergoes an expansion from state 1, where the specific internal energ
    7·1 answer
  • A tank contains initially 2500 liters of 50% solution. Water enters the tank at the rate of 25 iters per minute and the solution
    13·1 answer
  • Suppose a steam locomotive is rated at 7500 horsepower. If its efficiency is 6%, how much wood must be burned in a 3-hour trip?
    11·1 answer
  • A cylinder in space is of uniform temperature and dissipates 100 Watts. The cylinder diameter is 3" and its height is 12". Assum
    15·1 answer
  • A murder in a downtown office building has been widely publicized. You’re a police detective and receive a phone call from a dig
    9·2 answers
  • Michelle is the general manager of a power plant. This morning, she will meet with city officials to discuss environmental issue
    5·1 answer
  • A thin-walled tube with a diameter of 6 mm and length of 20 m is used to carry exhaust gas from a smoke stack to the laboratory
    7·1 answer
  • A tank contains 500 kg of a liquid whose specific gravity is 2. Determine the volume of the liquid in the tank.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!