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.