@DavidMcConnachi/

CSE110_Java_Arrays_loops_Find_Smallest

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class Main {
    public static void main(String []args){
        int [] numbers = new int[5];

        // Fill the array with random integers
        int index = 0;
        while(index < numbers.length) {
            numbers[index] = (int)(Math.random() * 100);
            System.out.println("numbers[" + index + "]: "
                               + numbers[index]);

            index = index + 1;
        }

        // Find the smallest integer in the array.
        int minimum = 101;
        for(int count = index; count >= 0; count--){
          int a = numbers[count];
          if (number[].hasnext)
            int b = numbers[count - 1];
          if (minimum < a && minimum < b){
            minimum = minimum;
          }else if (a > b){
            minimum = b;
          }else minimum = a;
        }


        System.out.println("Minimum: " + minimum);
    }
}