promotion image of download ymail app
Promoted

Are there any algorithms present in this program? Help is appreciated?

I don't know If there are any algorithms in my program below. If there are no algorithms in my program, how could I add algorithms to it?

// Print the operation that user is using AND print the answer (2 numbers)

if (numberFirst == 2) {

if (operation.equals("1"))

System.out.println("You are using addition." + " Your answer is " + (num1 + num2) + ".");

if (operation.equals("2"))

System.out.println("You are using subtraction." + " Your answer is " + (num1 - num2) + ".");

if (operation.equals("3"))

System.out.println("You are using multiplication." + " Your answer is " + (num1 * num2) + ".");

if (operation.equals("4"))

System.out.println("You are using division." + " Your answer is " + (num1 / num2) + ".");

if (operation.equals("5"))

System.out.println("You are using an exponent." + " Your answer is " + Math.pow(num1, num2) + ".");

}

// Print the operation that user is using AND print the answer (3 numbers)

if (numberFirst == 3) {

if (operation.equals("1"))

System.out.println("You are using addition." + " Your answer is " + (num1 + num2 + num3) + ".");

if (operation.equals("2"))

System.out.println("You are using subtraction." + " Your answer is " + (num1 - num2 - num3) + ".");

if (operation.equals("3"))

System.out.println("You are using multiplication." + " Your answer is " + (num1 * num2 * num3) + ".");

if (operation.equals("4"))

System.out.println("You are using division." + " Your answer is " + ((num1 / num2) / num3) + ".");

}

}

}

2 Answers

Relevance
  • 1 year ago
    Favorite Answer

    There are two basic algorithmic structures: iteration and recursion. Iteration is simply the repetition of processing steps. Recursion occurs when a method or function calling on itself. Your program is an example of the former rather than the latter.

    • Commenter avatarLogin to reply the answers
  • EddieJ
    Lv 7
    1 year ago

    Every program *IS* an algorithm -- a method used to accomplish something.

    Algorithms use 4 basic control constructs: Sequence, selection, iteration, and function calls.

Still have questions? Get your answers by asking now.