+ 4

Can someone debug this?

I dont know what importing modules should i add, and im a beginner at c#, this code is originally implemented in java, Thank you? ❀❀ https://code.sololearn.com/cG82bXodSZ5a/?ref=ap

29th Oct 2020, 1:18 AM
Lia Costa ✹
Lia Costa ✹ - avatar
7 Respostas
+ 2
Lia Costa ✹ there's no variable named output. Create a variable of type String. String output=""; for(int i =0 ; i< X.Count; i++ ) if(i < X.Count-1){ output+=""+X[i]+"\t"+", "; }else{ output+=""+X[i]; } Console.WriteLine("["+output+"]");
29th Oct 2020, 5:39 AM
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ - avatar
+ 3
That error was because of missing namespace and class. This one is correct though, using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sololearn { class myclass{ static void Main(string[] args) { int a=2,c =1; List<int> X = new List<int>(); X.Insert(0,0); //user input to m : int m = Convert.ToInt32(Console.ReadLine()); for(int n =0 ; n<m; n++) X.Insert(n+1,((a*X[n]+ c) % m)); for(int i =0 ; i< X.Count; i++ ) Console.Write(X[i]+"\t"); } } }
29th Oct 2020, 1:49 AM
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ - avatar
29th Oct 2020, 6:35 AM
Lia Costa ✹
Lia Costa ✹ - avatar
+ 1
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ can you add some commas in between and a bracket for the set of numbers on the output? Im not sure how to do that
29th Oct 2020, 2:46 AM
Lia Costa ✹
Lia Costa ✹ - avatar
+ 1
also thank you so much!
29th Oct 2020, 2:47 AM
Lia Costa ✹
Lia Costa ✹ - avatar
+ 1
Lia Costa ✹ it's too simple, there are others several ways too but this one is very simple. for(int i =0 ; i< X.Count; i++ ) if(i < X.Count-1){ output+=""+X[i]+"\t"+","; }else{ output+=""+X[i]; } Console.WriteLine("["+output+"]"); }
29th Oct 2020, 3:44 AM
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ - avatar
+ 1
https://code.sololearn.com/ci0S0S7vKb46/?ref=app it says output doesnt exist in the current context, im sorry im too slow
29th Oct 2020, 5:09 AM
Lia Costa ✹
Lia Costa ✹ - avatar