
Java Tutorial Sour Code: Algorithm
Consider the following example:
public class Minimum {
public static void main(String[] args) {
int a[] = { 23, 45, 71, 12, 87, 66, 20, 33, 15, 69 };
int min = a[0];
for (int i = 1; i < a.length; i++) {
if (a[i] < min) min = a[i];
}
System.out.println("The minimum value is: " + min);
}
}
Java Tutorial Sour Code: Algorithm
The Java code above returns the minimum value from an array of integers. There is no user input since the data from where to get the minimum is already in the program. That is, for the input and output properties. Each step in the program is precisely defined. Hence, it is definite. The declaration, the for loop and the statement to output will all take a finite time to execute. Thus, the finiteness property is satisfied. And when run, it returns the minimum among the values in the array so it is said to be effective.
Java Tutorial Sour Code: Algorithm
All the properties of an algorithm must be ensured in writing an algorithm.
No comments:
Post a Comment