Lesson 11 of 34

while आणि do-while Loops

8 min 25 XP

Loop किती वेळा चालेल हे आधी माहीत नसेल तेव्हा while वापरा. Condition false होईपर्यंत तो चालतो. Condition बदलायला विसरलात तर loop कधीच संपणार नाही!

Example: edit me and press Run

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

do-while आपली condition शेवटी तपासतो, म्हणून body किमान एकदा तरी चालतेच.

Example: edit me and press Run

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

n % 10 शेवटचा अंक देते आणि n / 10 तो काढून टाकते. Interviews मधले बहुतेक अंकांचे प्रश्न या दोन tricks ने सुटतात.

Challenge

+25 XP

एक संख्या वाचा आणि तिच्या अंकांची बेरीज print करा. Input: 4721 → Output: 14

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