008-002-007

Method Call with Arguments: Execute Methods by Passing Arguments in Recipe Card Class

Medium

Problem Description

Explanation: Calling Methods with Arguments

In this problem, you learned methods that receive arguments and methods without return values.

Key Learning Points

  1. Methods with Arguments: Format public void methodName(type argument)
  2. void Type: Use void when there's no return value
  3. Field Update: Can change field values inside methods

Code Example Explanation

public void addIngredient(String ingredient) {
    If (ingredients.isEmpty()) {
        Ingredients = ingredient;  // First ingredient
    } else {
        Ingredients += ", " + ingredient;  // From second onward
    }
}

This method:

  • void: No return value
  • String ingredient: Receives string argument
  • ingredients +=: Adds to existing string

Next Steps

Next, let's combine with methods that have return values!

.

Test Cases

※ Output examples follow programming industry standards

Input:
Expected Output:
Input:
Expected Output:
Input:
Expected Output:
Input:
Expected Output:
Input:
Expected Output:
Input:
Expected Output:
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 9 free executions remaining