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
igor_vitrenko [27]
2 years 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:
ahrayia [7]2 years ago
4 0

Answer:

import java.util.Scanner;

public class NumberPattern {  

public static void printDec(int num1 , int num2)

{

   if(num1<0)

    return ;

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

   printDec(num1-num2,num2);

}

public static void printInc(int num1, int num2)

{

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

curr = curr+num2;

printstart(num1,num2,curr);

}

public static void printstart(int num1 , int num2 , int curr)

{

    if(curr>num1)

     return;

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

    printstart(num1,num2,curr+num2);

}

public static void printNumPattern(int num1 , int num2)

{

  printDec(num1,num2);

  printInc(num1,num2);

}

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int num1;

int num2;

num1 = scnr.nextInt();

num2 = scnr.nextInt();

printNumPattern(num1, num2);

}

}

Explanation:

lilavasa [31]2 years ago
3 0

Answer:

See explaination

Explanation:

Code;

import java.util.Scanner;

public class NumberPattern {

public static int x, count;

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

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

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

count++;

printNumPattern(num1 - num2, num2);

} else {

x = 1;

if (count >= 0) {

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

count--;

if (count < 0) {

System.exit(0);

}

printNumPattern(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();

printNumPattern(num1, num2);

}

}

See attachment for sample output

You might be interested in
A piston-cylinder assembly contains 2 lb of air at a temperature of 540 °R and a pressure of 1 atm. The air compressed to a stat
dalvyx [7]

Answer:

123.9 Btu

Explanation:

The energy balance on the air is:

∆E = E2 − E1 = ∆KE + ∆PE + ∆U = Q + W

ignore  ∆KE and ∆PE,

W = ∆U − Q = m(u2 − u1) − Q;                               (u2 − u1 = 51.94 Btu/lb)

ideal gas properties is attached

W = (2 lb)(143.98 − 92.04) Btu/lb − (− 20 Btu) = 123.9 Btu

u2 − u1 ≈ cv(T2 − T1) = (0.173 Btu/lb°R)(840 − 540) °R = 51.9 Btu/lb

6 0
2 years ago
5 kg of steam contained within a piston-cylinder assembly undergoes an expansion from state 1, where the specific internal energ
GenaCL600 [577]

Answer:

Energy Transfer  =  350 kJ

Explanation:

The net work can be determined from an energy balance. That is, with assumption

∆KE + ∆PE + ∆U = Q − W

Where

∆KE = ∆PE = 0 (Since There is no significant change in the kinetic or potential energy of the steam)

The net work is the sum of the work associated with the paddlewheel Wpw

and the work done on the piston Wpiston:

W = Wpw + Wpiston

From the given information, Wpw= −18.5 kJ,

Collecting results:

Wpw + Wpiston = Q − ∆U

Wpiston = Q − ∆U − Wpw= Q − m (u2− u1) − Wpw

Where Q=80kJ, m=5kg, u2 = 2659.6 kJ/kg,  u1 = 2709.9 kJ/kg

= 80 kJ − 5 kg (2659.6 − 2709.9)kJ/kg − ( −18. 5 kJ)

= 350 kJ

4 0
2 years ago
generally compound curves are not filtered recommended for A. Road B. water way C. underground road D. rail way​
vfiekz [6]

Answer:

C. underground road

Explanation:

Generally compound curves are not filtered and recommended for use in an underground road. However, they are best used in the road, water way, and rail way.

3 0
2 years ago
Show that a chirped Gaussian pulse is compressed initially inside a single-mode fiber when ftC &lt; 0. Derive expressions for th
Damm [24]

Answer:

Given in diagram

8 0
2 years ago
A 1020 CD steel shaft is to transmit 15 kW while rotating at 1750 rpm. Determine the minimum diameter for the shaft to provide a
vladimir2022 [97]

Answer:

diameter is 14 mm

Explanation:

given data

power = 15 kW

rotation N = 1750 rpm

factor of safety = 3

to find out

minimum diameter

solution

we will apply here power formula to find T that is

power = 2π×N×T / 60    .................1

put here value

15 ×10^{3} = 2π×1750×T / 60

so

T = 81.84 Nm

and

torsion = T / Z                        ..........2

here Z is section modulus i.e = πd³/ 16

so from equation 2

torsion = 81.84 / πd³/ 16

so torsion = 416.75 / / d³     .................3

so from shear stress theory

torsion = σy / factor of safety

so here σy = 530 for 1020 steel

so

torsion = σy / factor of safety

416.75 / d³ = 530 × 10^{6} / 3

so d = 0.0133 m

so diameter is 14 mm

3 0
2 years ago
Other questions:
  • Water is the working fluid in an ideal Rankine cycle. The condenser pressure is 8 kPa, and saturated vapor enters the turbine at
    10·1 answer
  • A meter stick can be read to the nearest millimeter and a travelling microscope can be read to the nearest 0.1 mm. Suppose you w
    11·1 answer
  • A driver traveling at 65 mi/h rounds a curve on a level grade to see a truck overturned across the roadway at a distance of 350
    13·1 answer
  • Given a 5x5 matrix for Playfair cipher a. How many possible keys does the Playfair cipher have? Ignore the fact that some keys m
    6·1 answer
  • Consider a very long rectangular fin attached to a flat surface such that the temperature at the end of the fin is essentially t
    9·1 answer
  • Current density is given in cylindrical coordinates as J = −106z1.5az A/m2 in the region 0 ≤ rho ≤ 20 µm; for rho ≥ 20 µm, J = 0
    13·1 answer
  • You are an electrician on the job. The electrical blueprint shows that eight 500-W lamps are to be installed on the same circuit
    11·1 answer
  • Five Kilograms of continuous boron fibers are introduced in a unidirectional orientation into of an 8kg aluminum matrix. Calcula
    9·1 answer
  • When encountering low visibility from rain or fog, you should use your ____.
    12·1 answer
  • Interlocking stacked material is done by​ _____.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!