+ 2

What is wrong with this code, this code is giving the compilation error?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[] arr={1,2,3,4,5,6}; Console.Write("Enter number to shift the array: "); int d=int.Parse(Console.ReadLine()); for(int i=0;i<d;i++) { int temp=arr[0]; for(int j=0;j<arr.Length-1;j++) { arr[j]=arr[j+1]; } arr[arr.Length-1]=temp; } Console.ReadLine(); } } }

10th Nov 2018, 6:26 AM
Adnan Awan
Adnan Awan - avatar
5 Respuestas
+ 1
sai he
10th Nov 2018, 2:28 PM
Syed Waleed
Syed Waleed - avatar
+ 1
There is nothing wrong with this code. It works fine. If sololearn does have problems with its internet connection you sometime get a compilation error as result although the code is fine. You also can get a compilation error if the loop takes to much time to run. I used 3 as input. In sololearn I removed the last //Console.ReadLine because you do not need it on sololearn. And I added a output-loop so I can prove the array was shifted. https://code.sololearn.com/cCKvpNd33x4L
10th Nov 2018, 9:19 PM
sneeze
sneeze - avatar
10th Nov 2018, 2:03 PM
Adnan Awan
Adnan Awan - avatar
10th Nov 2018, 2:04 PM
Adnan Awan
Adnan Awan - avatar
0
but compilation error occurs...?
10th Nov 2018, 2:29 PM
Adnan Awan
Adnan Awan - avatar