QuestionAsk Questions?

View Answers

July 18, 2009 at 5:10 PM

Hi Friend,

Try the following code:

public class MaxMin{

public static void main(String[] args) {

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

int max = num[0];

int min = num[0];

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

if (num[i] > max) {

max = num[i];

}

}

System.out.println("Largest Number: "+max);

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 code:

public class MaxMin{

public static void main(String[] args) {

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

int max = num[0];

int min = num[0];

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

if (num[i] > max) {

max = num[i];

}

}

System.out.println("Largest Number: "+max);

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: