004-008-002

Multidimensional Array: Weekly Menu Table

Easy

Problem Description

Multidimensional Array: Weekly Menu Table

Learning Objective: Create 2D string array and store data

Manage weekly menu table. Create 2D array to record menus by combination of day and meal time (breakfast, lunch, dinner).

Input

Line 1: Number of days n (1-3)
Following lines: Menus for n days (3 meals per day: breakfast lunch dinner)

Output

=== Weekly Menu ===
Day 1: Breakfast[breakfast] Lunch[lunch] Dinner[dinner]
Day 2: Breakfast[breakfast] Lunch[lunch] Dinner[dinner]
...
━━━━━━━━━━━━━━━━
Total: [n] days, [n×3] meals
```java

## Examples

### Example 1: 2 Days of Menus
Input:
```java
2
bread salad curry
rice ramen sushi
```java
Output:
```java
=== Weekly Menu ===
Day 1: Breakfastbread Lunchsalad Dinnercurry
Day 2: Breakfastrice Lunchramen Dinnersushi
━━━━━━━━━━━━━━━━
Total: 2 days, 6 meals

Test Cases

※ Output examples follow programming industry standards

Input:
2
Bread Salad Curry
Rice Ramen Sushi
Expected Output:
=== Weekly Menu ===
Day 1: BreakfastBread LunchSalad DinnerCurry
Day 2: BreakfastRice LunchRamen DinnerSushi
━━━━━━━━━━━━━━━━
Total: 2 days, 6 meals
Input:
1
Toast Soup Steak
Expected Output:
=== Weekly Menu ===
Day 1: BreakfastToast LunchSoup DinnerSteak
━━━━━━━━━━━━━━━━
Total: 1 days, 3 meals
Input:
3
Onigiri Udon Yakiniku
Sandwich Set Meal Hot Pot
Cereal Pasta Sashimi
Expected Output:
=== Weekly Menu ===
Day 1: BreakfastOnigiri LunchUdon DinnerYakiniku
Day 2: BreakfastSandwich LunchSet DinnerMeal
Day 3: BreakfastHot LunchPot DinnerCereal
━━━━━━━━━━━━━━━━
Total: 3 days, 9 meals
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 日数を読む
int n = sc.nextInt();
// 複数日の3食分のマルチディメンショナルデータストレージ用に2次元配列を作成
String[][] menu = new String[n][3];
// メニューを読む
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
menu[i][j] = sc.next();
}
}
// 計算結果をコンソール出力に表示
System.out.println("=== Weekly Menu ===");
String[] labels = {"Breakfast", "Lunch", "Dinner"};
for (int i = 0; i < n; i++) {
System.out.print("Day " + (i + 1) + ": ");
for (int j = 0; j < 3; j++) {
System.out.print(labels[j] + menu[i][j]);
// [if文] 条件分岐
if (j < 2) System.out.print(" ");
}
System.out.println();
}
System.out.println("━━━━━━━━━━━━━━━━");
System.out.println("Total: " + n + " days, " + (n * 3) + " meals");
}
}

0 B / 5 MB

You have 10 free executions remaining