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
igor_vitrenko [27]
3 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]3 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]3 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
Assume that light of wavelength 6000A is coming from a star. What is the limit of resolution of a telescope whose objective has
Paul [167]

Answer:

θ=0.0288 radian

Explanation:

resolution limit is the minimum angular separation of  two sources that can be viewed  distinctly    by telescope

\theta =\frac{1.22\times \lambda}{D}

\lambda=6000\times 10^{-8} cm=6 \times 10^{-5} cm

d=100 inch=100\times 2.54=254cm

\theta = \frac{1.22 \times 6 \times 10^{-5}}{254}

θ=0.0288 radian

4 0
3 years ago
Some connecting rods have ____ to help lubricate the cylinder wall or piston pin.
Ket [755]

Answer:

some connecting rods have spit holes

4 0
4 years ago
Read 2 more answers
True or False - Blueprints can be drawn both by hand and on a computer
Orlov [11]

Answer:

The answer is true.

Explanation:

Most of it is done in computer, but it can also be drawn out by hand.

6 0
3 years ago
Read 2 more answers
How does sea navigation work?
ahrayia [7]

Answer:

a clock

Explanation:

you use a clock in water

3 0
3 years ago
In order to be a Mechanical Engineer, you need to:
djyliett [7]

Answer:

3

Explanation:

it is compulsory to have a bachelor's degree

4 0
3 years ago
Read 2 more answers
Other questions:
  • 4. The friction point is the point
    12·1 answer
  • A square power screw has a mean diameter of 30 mm and a pitch of 4 mm with single thread. The collar diameter can be assumed to
    14·1 answer
  • How do I cancel Trial subscription
    15·1 answer
  • Which of the following are the main psychological domains?
    7·1 answer
  • Please please help please with this this is the link for the story PLEASE PLEASE HELP PLEASE PLEASE help please
    7·1 answer
  • Water vapor at a rate of 40,000 kg/h and at 8 MPa and 500 C enters an adiabatic turbine and leaves the turbine at 40 kPa as satu
    8·1 answer
  • Electronic components are often mounted with good heat conduction paths to a finned aluminum base plate, which is exposed to a s
    14·1 answer
  • Why might there be multiple foremen on one work site?
    11·1 answer
  • Tech A says that a mechanical pressure regulator exhausts excess fluid back to the transmission pan. Tech B says that if the tra
    9·1 answer
  • QUESTION 1
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!