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

एक method static long factorial(int n) लिखें। 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.