Question: What is the output of the following code: Java C# class Main { public static void main(String[] args) { int[] myArray =

What is the output of the following code:

JavaC#

class Main {

  public static void main(String[] args) {

    int[] myArray = new int[5];

    try {

      for(int i=0;i<=5;i++) {

        myArray[i]=i;

      }

      System.out.println(myArray[3]);

    }

    catch(Exception e) {

      System.out.println("Something went wrong");

    }

  }

}

using System;

class MainClass {

  public static void Main (string[] args) {

    int[] myArray = new int[5];

    try {

      for(int i=0;i<=5;i++) {

        myArray[i]=i;

      }

      Console.WriteLine(myArray[3]);

    }

    catch(Exception e) {

      Console.WriteLine("Something went wrong");

    }

  }

}

Step by Step Solution

3.41 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!