Fixing functionality
I really liked your attempt to solve the problem, it was almost correct. Let's see what was wrong:
for (int i = 1; i < 6; i++) {
System.out.println("["+i+"] "+flvr[i]);
for (int j = 1; j < price[i].length; j++) {
System.out.print(+price[i][j]+ "\t");
}
}
In the first print, you're using println, so the prices will be one line below of the coffee name. Change it to print.
After you print the prices, you're not adding a new line, so the next coffee and its prices will be printed in the same line as the previous one. Add a println to the outer loop.
Fixed code:
for (int i = 1; i < 6; i++) {
System.out.print("["+i+"] "+flvr[i]);
for (int j = 1; j < price[i].length; j++) {
System.out.print(+price[i][j]+ "\t");
}
System.out.println();
}
Output:
[1] Cookies n' Cream100.0 50.0
[2] Okinawa125.0 75.0
[3] Dark Chocolate120.0 65.0
[4] Wintermelon120.0 65.0
[5] Matcha120.0 65.0
Formatting improvements
You can use System.out.printf to add some padding to the coffee name and prices instead of '\t':
// Print the header
System.out.printf("%-23s%10s %11s\n", "MILKTEA FLAVORS", "Large", "Small");
for (int i = 1; i < 6; i++) {
// Add a right padding of 20 spaces in the coffee name
System.out.printf("[%d] %-20s", i, flvr[i]);
for (int j = 1; j < price[i].length; j++) {
// Add a left padding of 10 spaces in each price
System.out.printf("%10.2f ", price[i][j]);
}
System.out.println();
}
New output:
MILKTEA FLAVORS Large Small
[1] Cookies n' Cream 100.00 50.00
[2] Okinawa 125.00 75.00
[3] Dark Chocolate 120.00 65.00
[4] Wintermelon 120.00 65.00
[5] Matcha 120.00 65.00
Data representation
Since Java is an object-oriented language, you can use objects to represent each coffee.
class Coffee {
final String name;
final double largePrice;
final double smallPrice;
public Coffee(String name, double largePrice, double smallPrice) {
this.name = name;
this.largePrice = largePrice;
this.smallPrice = smallPrice;
}
}
Instantiating them:
final Coffee[] coffees = {
new Coffee("Cookies n' Cream", 100.00, 50.00),
new Coffee("Okinawa", 125.0, 75.0),
new Coffee("Dark Chocolate", 120.0, 65.0),
new Coffee("Wintermelon", 120.0, 65.0),
new Coffee("Matcha", 120.0, 65.0),
};
Printing them:
for (int i = 0; i < coffees.length; i++) {
final Coffee coffee = coffees[i];
System.out.printf("[%d] %-20s", i, coffee.name);
System.out.printf("%10.2f ", coffee.largePrice);
System.out.printf("%10.2f", coffee.smallPrice);
System.out.println();
}