# 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"))

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) + ".");

}

}

}

Relevance

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.

• Login to reply the answers
• Every program *IS* an algorithm -- a method used to accomplish something.

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

• Login to reply the answers