Lesson 19 of 34

Return Values

9 min 30 XP

Value परत देण्यासाठी void ऐवजी तिचा type (int, double, boolean, String) लिहा आणि return वापरा. return चालताच method संपते.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

चांगली method एकच काम करते आणि तिचे नाव ते काम सांगते: isPrime, findMax, calculateTax.

Challenge

+30 XP

static long factorial(int n) ही method लिहा. main() मध्ये n वाचा आणि factorial(n) print करा. Input: 5 → Output: 120

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.