English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Working on a Java program that we have to create max and min and intiate program to determine what integers are max and which are min using if statements.

2006-10-12 18:02:42 · 2 answers · asked by azhi_saleem 1 in Computers & Internet Programming & Design

2 answers

if your only comparing two values use the Math class. Otherwise i would put all the values in an array and then move through it looking for the largest and smallest values.

ex.
int[] array = {1, 2, 3, 4};
int min = array[0]; // assume first value is largest and smallest
int max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) max = array[i];
if (array[i] < min) min = array[i];
}

(not tested but should give you an idea)

2006-10-12 19:19:13 · answer #1 · answered by Brady 3 · 0 0

Please give the full detail.
JP

2006-10-12 18:24:39 · answer #2 · answered by JP 3 · 0 0

fedest.com, questions and answers