Observe the following coding in java & find out the output:
class Matrix{
void display()
{
int a[]={1,6,3,4,0,12,2,5};
int l=a.length;
for(int i=0;i<l;i++){
switch(i)
{
case 0:a[i]=a[i+1];
case 2:a[i]=a[i+2];
case 6:a[i++]=a[i];
break;
case 7:a[i]=a[i-1];
default:a[i]=a[i++];
}}
System.out.print("{");
for(int i=0;i<l;i++)
System.out.print(a[i]+",");
System.out.println("}");
}
public static void main(String args[])
{
new Comprogzz().display();
}
}
Log on to comprogzz.in to learn about programming in Java ;)
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
In the first iteration of the f o r loop, value of i = 0 . Therefore, we will execute c a s e 0 .
In this case,
In other words, the value of a [ 0 + 1 ] = a [ 1 ] is placed in a [ 0 ] . 6 is placed in a [ 0 ] .
That's basically it, we don't have to look at any other options as there is only one option whose first value is 6 .