Static methods should be used with the complete definition so
runIntFinder should be invoked like:
IntFinder.runIntFinder();
As for statics, they should only be used when the analysis/design requires
it, a habit of using statics is a bad habit.
Code:
public class IntFinder {
public int largest(int[] a) {
int largest = Integer.MIN_VALUE;
for ( int i = 0 ; i < a.length ; i++ ) {
if ( a[i] > largest )
largest = a[i];
}
return largest;
}
}
public class IntFinderDriver {
public int runIntFinder() {
int[] ia = new int[5];
ia[0] = 15;
ia[1] = 78858;
ia[2] = 99;
ia[3] = 55;
ia[4] = 19;
IntFinder inf=new IntFinder();
return inf.largest(ia);
}
public static void main(String[] args){
IntFinderDriver ifd=new IntFinderDriver();
System.out.print(ifd.runIntFinder());
}
} // end class
Bookmarks