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
Not sure which one....
Airida [17]
I think downwards as that's how most saw's work.
4 0
3 years ago
Technologies that allow for instant worldwide communication include
hram777 [196]

Answer:

mobile phones and internet access

Explanation:

I got it right on my quiz

7 0
3 years ago
Read 2 more answers
The Energy Losses Associated with Valves and Fittings: a)- are generally associated with a K factor b)- are generally associated
madam [21]

Answer:

a)Are generally associated with factor.

Explanation:

We know that losses are two types

1.Major loss  :Due to friction of pipe surface

2.Minor loss  :Due to change in the direction of flow

As we know that when any hindrance is produced during the flow of fluid then it leads to generate the energy losses.If flow is along uniform diameter pipe then there will not be any loss but if any valve and fitting placed is the path of fluid flow due to this direction of fluid flow changes and  it produce losses in the energy.

Lot' of experimental data tell us that loss in the energy due to valve and fitting are generally associated with K factor.These losses are given as

Losses=K\dfrac{V^2}{2g}

8 0
3 years ago
Which of the following is NOT true about hydraulic valves? A. Directional control valves determine the path of a fluid in a give
Lelechka [254]

Answer: Option D is not true of hydraulic valves. A hydraulic valve is a device that can change the opening degree of liquid flow path

Explanation:

The pilot check valve allows flow of liquid in one direction and blocks flow in the opposite direction

5 0
3 years ago
A company purchases a certain kind of electronic device from a manufacturer. The manufacturer indicates that the defective rate
olga2289 [7]

Answer:

1) The probability of at least 1 defective is approximately 45.621%

2) The probability that there will be exactly 3 shipments each containing at least 1 defective device among the 20 devices that are tested from the shipment is approximately 16.0212%

Explanation:

The given parameters are;

The defective rate of the device = 3%

Therefore, the probability that a selected device will be defective, p = 3/100

The probability of at least one defective item in 20 items inspected is given by binomial theorem as follows;

The probability that a device is mot defective, q = 1 - p = 1 - 3/100 = 97/100 = 0.97

The probability of 0 defective in 20 = ₂₀C₀(0.03)⁰·(0.97)²⁰ ≈ 0.543794342927

The probability of at least 1 = 1 - The probability of 0 defective in 20

∴ The probability of at least 1 = 1 - 0.543794342927 = 0.45621

The probability of at least 1 defective ≈ 0.45621 = 45.621%

2) The probability of at least 1 defective in a shipment, p ≈ 0.45621

Therefore, the probability of not exactly 1 defective = q = 1 - p

∴ q ≈ 1 - 0.45621 = 0.54379

The probability of exactly 3 shipment with at least 1 defective, P(Exactly 3 with at least 1) is given as follows;

P(Exactly 3 with at least 1) = ₁₀C₃(0.45621)³(0.54379)⁷ ≈ 0.160212

Therefore, the probability that there will be exactly 3 shipments each containing at least 1 defective device among the 20 devices that are tested from the shipment is 16.0212%

4 0
3 years ago
Other questions:
  • In C++ the declaration of floating point variables starts with the type name float or double, followed by the name of the variab
    14·1 answer
  • Mr.Haussman has 17 students in his class
    14·2 answers
  • The cross-section of a rough, rectangular, concrete() channel measures . The channel slope is 0.02ft/ft. Using the Darcy-Weisbac
    8·1 answer
  • What substance do humans give to livestock to help them stay healthy?
    5·1 answer
  • How to update android 4.4.2 to 5.1 if there isnt any update available​
    15·2 answers
  • Is a compass a analog or a digital sensor?
    14·1 answer
  • Which of the following is an example of a pulley?
    10·2 answers
  • How do guest room hotel smoke alarms work and differ then regular home versions?
    10·2 answers
  • Good night. I need to go to bed. Byeeeeeeeeeeeee.​
    15·1 answer
  • Why is “land-use planning” an appropriate name for urban planning?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!