Real World Example

Monthly Sales Report

Analytics dashboards (for example a Swiggy restaurant partner app) loop over sales data to compute totals, find the best day and skip holidays.

Example

public class Main {
    public static void main(String[] args) {
        String[] days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
        int[] orders = {42, 38, 0, 51, 67, 89, 95};   // Wed closed

        int total = 0, openDays = 0, bestIndex = 0;
        for (int i = 0; i < days.length; i++) {
            if (orders[i] == 0) {
                System.out.println(days[i] + ": closed");
                continue;
            }
            total += orders[i];
            openDays++;
            if (orders[i] > orders[bestIndex]) bestIndex = i;
            System.out.println(days[i] + ": " + "#".repeat(orders[i] / 10) + " " + orders[i]);
        }
        System.out.println("Total orders : " + total);
        System.out.printf("Average/day  : %.1f%n", (double) total / openDays);
        System.out.println("Best day     : " + days[bestIndex]);
    }
}

Output

Mon: #### 42
Tue: ### 38
Wed: closed
Thu: ##### 51
Fri: ###### 67
Sat: ######## 89
Sun: ######### 95
Total orders : 382
Average/day  : 63.7
Best day     : Sun