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
Types of technology include:
Anastaziya [24]
The answer is D-all choices
3 0
3 years ago
A cantilever beam of length L = 70 in is made from two side-by-side structural-steel channels of size 3 in weighing 5.0 lbf/ft.
natali 33 [55]

Answer:

of 5 lb/ft and a concentrated service live load at midspan. .... length = 12 feet) to support a uniformly distributed load. Taking ... w 7..'{ 'f.- ~ s-·. 344 ft-kip. Fy : s-o ks I. 299 ft-kip. Li.. ::::- I 2.. }-t-. 150 ft-kip ..... The concrete and reinforcing steel properties are ... Neglecting beam self-weight . and based only on the ...... JI : Lf, 2. l.. ;VI.

Explanation:

6 0
3 years ago
A three-point bending test was performed on an aluminum oxide specimen having a circular cross section of radius 5.6 mm; the spe
ankoles [38]

Answer:

F =  8849 N

Explanation:

Given:

Load at a given point = F =  4250 N

Support span = L = 44 mm

Radius = R = 5.6 mm

length thickness of tested material = 12 mm

First compute the flexural strength for circular cross section using the formula below:

σ_{fs} = F_{f} L / \pi  R^{3}

σ = FL / π R³

Putting the given values in the above formula:

σ = 4250 ( 44 x 10⁻³ ) / π  ( 5.6 x 10⁻³ ) ³

  = 4250 ( 44 x 10⁻³ )  / 3.141593 ( 5.6 x 10⁻³ ) ³

  = 4250 (44 x 1 /1000 )) / 3.141593 ( 5.6 x 10⁻³ ) ³

  = 4250 ( 11 / 250  ) / 3.141593 ( 5.6 x 10⁻³ ) ³

  = 187 / 3.141593 ( 5.6 x 1 / 1000 ) ³

  = 187 / 3.141593 (0.0056)³

  = 338943767.745358

  = 338.943768 x 10⁶

σ = 338 x 10⁶ N/m²

Now we compute the load i.e. F from the following formula:

F_{f} = 2 σ_{fs} d³/3 L

F = 2σd³/3L

  = 2(338 x 10⁶)(12 x 10⁻³)³ / 3(44 x 10⁻³)

  = 2 ( 338 x 1000000 ) ( 12 x 10⁻³)³ / 3 ( 44 x 10⁻³)

  = 2 ( 338000000 ) ( 12 x 10⁻³)³ / 3 ( 44 x 10⁻³)

  = 676000000 ( 12 x 10⁻³)³ / 3 ( 44 x 10⁻³)

  = 676000000 ( 12  x  1/1000  )³ / 3 ( 44 x 10⁻³)

  = 676000000 (  3  / 250  )³ / 3 ( 44 x 10⁻³)

  = 676000000 (  27  / 15625000 )  / 3 ( 44 x 10⁻³)

  = 146016  / 125 / 3 ( 44 x 1 / 1000  )

  = ( 146016  / 125 ) /  (3 ( 11 /  250 ))

  =  97344  / 11

F =  8849 N

4 0
3 years ago
Provide an argument justifying the following claim: The average (as defined here) of two Java ints i and j is representable as a
ahrayia [7]

Answer:

public static int average(int j, int k) {

return (int)(( (long)(i) + (long)(j) ) /2 );

}

Explanation:

The above code returns the average of two integer variables

Line 1 of the code declares a method along with 2 variables

Method declared: average of integer data type

Variables: j and k of type integer, respectively

Line 2 calculates the average of the two variables and returns the value of the average.

The first of two integers to average is j

The second of two integers to average is k

The last parameter ensures average using (j+k)/2

3 0
3 years ago
What is the ratio between driver gear A with 60 teeth and driven gear B with 180 teeth?
Anna71 [15]
The ratio between a and b is 1/3
3 0
3 years ago
Other questions:
  • A wooden cylinder (0 02 x 0 02 x 0 1m) floats vertically in water with one-third of ts length immersed. a)-Determine the density
    7·1 answer
  • A DNS record that's used to redirect traffic from one domain name to another is known as a _______ record.
    11·1 answer
  • You are given that kc = 10-1 kg eq-1 min-1, ku = 10-3 kg2 eq-2 min-1 and [A]0 = 10 eq kg-1, where kc is the rate constant for a
    15·1 answer
  • A Barnes and Books is interested in purchasing a two-story building for a new
    5·1 answer
  • Select three functions of catalysts.
    9·1 answer
  • A front wheel drive vehicle with four wheel disc brakes is pulling to the left. Tech A says an external kink or internal restric
    13·1 answer
  • What car has autopilot?
    14·2 answers
  • 3. What is a caliber (relate it to rockets)
    14·1 answer
  • Their game off badminton is always on Tuesday
    11·1 answer
  • 3. (5%) you would like to physically separate different materials in a scrap recycling plant. describe at least one method that
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!