+ 3

Help with cycle C#

I have code: int number = 11; for (int x = 1; number >= x; x++){ if (x % 5 != 0) Console.Write(x);} How change example 5, 10... to “-“? Result: 1234-6789-11

11th Jan 2021, 10:28 AM
Nazar Sumyk
Nazar Sumyk - avatar
2 Antworten
+ 5
Just use "else" after "if" with Console.Write("-"); if(x%5 != 0) Console.Write(x); else Console.Write("-");
11th Jan 2021, 10:37 AM
Padala Vamsi
Padala Vamsi - avatar
+ 1
omg... rly, thank you :)
11th Jan 2021, 10:42 AM
Nazar Sumyk
Nazar Sumyk - avatar