Answer the question
In order to leave comments, you need to log in
Java program to find smallest number?
A simple task that led me a little into a stupor.
public static void main(String[] args) {
int a, b, c, d;
int min = 0;
a = 12;
b = 22;
c = 33;
d = 11;
if(a>b){
min = b;
}
if(min>c){
min = c;
}
if(min>d){
min = d;
}
System.out.println("Наименьшее число "+min);
}
Answer the question
In order to leave comments, you need to log in
1) Put the values in an array
2) Walk through the array, remembering the minimums
min = array[0];
for (int i=1; i < array.length; i++) {
if (array[i+1] < min)
min = array[i+1]
}
int[] numbers = {9,8,7,6,5,4,3,2,1} ;
int min = numbers[0];
for ( int n : numbers ) {
min = min < n ? min : n;
}
System.out.println("Min = " + min);
int[] numbers = {9,8,7,6,5,4,3,2,1} ;
Arrays.sort(numbers);
int min = numbers[0];
System.out.println("Min = " + min);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question