डाइस गेम
आप डाइस थ्रोइंग पर आधारित एक वीडियो गेम बनाना चाहते हैं. इसके लिए, आप ऐसा वर्कफ़्लो बनाना चाहते हैं जो डाइस के result के आधार पर अलग-अलग आउटपुट दे. जब डाइस 20 दिखाए, तो उसे critical hit माना जाएगा.
यह अभ्यास पाठ्यक्रम का हिस्सा है
इंटरमीडिएट Java
अभ्यास निर्देश
- प्रिंट करने से पहले यह जाँचने के लिए सही ऑपरेटर का उपयोग करें कि
result20है. - ऑपरेटर को सही तरह घेरें ताकि केवल तब प्रिंट हो जब
result10से कम या बराबर हो.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
class DiceGame {
public static void main(String[] args) {
int result = 5;
// Use the correct operator to make sure it's a critical hit
if (result ____ 20) {
System.out.println("That's a critical hit!");
}
// Check if result is lower or equal to ten
if (____ <= ____) {
System.out.println("Unfortunately, you miss");
}
}
}