Java: Find the Bug

This Java quiz shows small programs with a real bug inside, the kind you meet in code reviews and debugging interviews. Predict what actually happens, then pick the fix that makes the code do what was intended.

कठिन 10 सवाल ~8 मिनट पास होने के लिए 80% Java 17

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 10

This should print the sum of the array. What happens instead?

public class Main {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 5};
        int sum = 0;
        for (int i = 0; i <= nums.length; i++) {
            sum += nums[i];
        }
        System.out.println(sum);
    }
}
जवाब दिखाएं

B. ArrayIndexOutOfBoundsException Valid indexes go from 0 to nums.length - 1. With <=, the last iteration reads nums[5] and throws. Use < or a for-each loop.

इस क्विज़ में क्या है

  • Off-by-one loops and missing initialization
  • == vs equals() and overloading equals by mistake
  • Ignored return values of immutable String methods
  • Integer division and integer overflow in calculations
  • char arithmetic and silently swallowed exceptions

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।