QuestionAsk Questions?

You are to choose between two procedures, both of which compute the mini-mum value in an array of integers. One procedure returns the smallest integer if its array argument is empty. The other requires a nonempty array. Which procedure should you choose and why?

View Answers

February 15, 2010 at 5:02 PM

Hi Friend,

Try the following:

public class Small{

public static void main(String[] args) {

int []num={100,20,152,24,456,651,258,35};

int min = num[0];

for (int i=1; i<num.length; i++) {

if (num[i]< min) {

min = num[i];

}

}

System.out.println("Smallest Number: "+min);

}

}

Thanks

Try the following:

public class Small{

public static void main(String[] args) {

int []num={100,20,152,24,456,651,258,35};

int min = num[0];

for (int i=1; i<num.length; i++) {

if (num[i]< min) {

min = num[i];

}

}

System.out.println("Smallest Number: "+min);

}

}

Thanks

Related Tutorials/Questions & Answers: