public class SmallestNumber {
public static void main(String[] args) {
int[] arr = {12, 31, 25, 17, 40, 9, 34};
int min = arr[0];
for(int i=1; i<arr.length; i++){
if(arr[i] < min){
min = arr[i];
}
}
System.out.println("Smallest number in the array: " + min);
}
}Smallest number in the array: 9arr. We initialize a variable min with the first element of the array. Then, we loop through the rest of the array and compare each element with min. min, we update the value of min. Finally, we print the value of min, which is the smallest element of the array.