java smallest sub number in array code example

Example 1: java find biggest number in array

for (int counter = 1; counter < decMax.length; counter++)
{
     if (decMax[counter] > max)
     {
      max = decMax[counter];
     }
}

System.out.println("The highest maximum for the December is: " + max);

Example 2: how to find the smallest numbers in an arraylist java

import java.util.ArrayList;
 
import java.util.Scanner;
 
public class IndexOfSmallest {
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
      
        ArrayList<Integer> list = new ArrayList<>();
 
        while (true) {
 
            int input = Integer.valueOf(scanner.nextLine());
 
            if (input == 9999) {
 
                break;
 
            }
 
            list.add(input);
 
        }
 
        System.out.println("");
 
        int smallest = list.get(0);
 
        int index = 0;
 
        while (index < list.size()) {
 
            if (list.get(index) < smallest) {
 
                smallest = list.get(index);
 
            }
 
            index++;
 
        }
 
        System.out.println("Smallest number: " + smallest);
 
        index = 0;
 
        while (index < list.size()) {
 
            if (list.get(index) == smallest) {
 
                System.out.println("Found at index: " + index);
 
            }
 
            index++;
 
        }
 
    }
 
}

Tags:

Java Example