Untitled
unknown
plain_text
3 years ago
861 B
5
Indexable
public class Prices {
public static void main(String[] args) {
// Declare and initialize an array of 20 prices
double[] prices = {500.50, 1500.25, 200.70, 750.00, 100.00, 300.00, 600.75, 400.80, 1000.50, 50.25, 900.00, 1200.30, 250.50, 800.00, 350.25, 600.00, 950.75, 1800.50, 300.90, 400.25};
// Calculate the sum of all prices in the array
double sum = 0.0;
for (double price : prices) {
sum += price;
}
// Display the sum of all prices
System.out.println("The sum of all prices is: $" + sum);
// Display all values less than 500.00
System.out.println("Values less than $500.00:");
for (double price : prices) {
if (price < 500.00) {
System.out.println("$" + price);
}
}
}
}
Editor is loading...