Login Register






[Challenge:1] Multiples of 3 and 5 filter_list
Author
Message
RE: [Challenge:1] Multiples of 3 and 5 #17
(12-08-2016, 09:36 AM)Bish0pQ Wrote: C#

Spoiler:
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Multiples {    class Program    {        static void Main(string[] args)        {            //Variables            int intSum = 0;            string strSum = string.Empty;            //Calculate sum            for (int i = 0; i < 1000; i++)            {                if (i % 3 == 0 || i % 5 == 0)                {                    intSum += i;                    strSum = intSum.ToString();                                    }            }            Console.WriteLine("The sum is {0}", strSum); //Write sum result            //Reverse the number (another loop, boring I know)            string strSumReversed = string.Empty;            int intCount = strSum.Length;            for (int x = 0; x < strSum.Length; x++)            {                strSumReversed = strSumReversed + strSum.Substring(intCount -1, 1);                intCount = intCount - 1;            }            Console.WriteLine("The sum reversed is: {0}", strSumReversed); //Write reversed result            Console.ReadLine();                      }        }    }

String's are immutable in .NET, but why didn't you use the for loop variable here?
Code:
for (int x = 0; x < strSum.Length; x++) { strSumReversed = strSumReversed + strSum.Substring(intCount -1, 1); intCount = intCount - 1; }

Instead of keeping track of your own variable?
(This post was last modified: 12-08-2016, 05:35 PM by bitm0de.)
- mostly braindead monkeys on this forum.

Reply





Messages In This Thread
[Challenge:1] Multiples of 3 and 5 - by Vi-Sion - 11-25-2016, 08:23 PM
RE: Multiples of 3 and 5 - by Pikami - 11-25-2016, 08:57 PM
RE: Multiples of 3 and 5 - by Vi-Sion - 11-25-2016, 09:01 PM
RE: Multiples of 3 and 5 - by Pikami - 11-25-2016, 10:08 PM
RE: Multiples of 3 and 5 - by DarkMuse - 11-25-2016, 09:58 PM
RE: Multiples of 3 and 5 - by Nyx - 11-25-2016, 10:06 PM
RE: Multiples of 3 and 5 - by Inori - 11-25-2016, 10:39 PM
RE: Multiples of 3 and 5 - by Nil - 11-25-2016, 10:51 PM
RE: Multiples of 3 and 5 - by Vi-Sion - 11-26-2016, 01:26 PM
RE: Multiples of 3 and 5 - by bitm0de - 11-27-2016, 12:46 AM
RE: Multiples of 3 and 5 - by Pikami - 11-27-2016, 10:17 AM
RE: Multiples of 3 and 5 - by Vi-Sion - 11-27-2016, 01:17 PM
RE: Multiples of 3 and 5 - by lux - 11-30-2016, 09:29 PM
RE: Multiples of 3 and 5 - by Vi-Sion - 11-30-2016, 10:11 PM
RE: [Challenge:1] Multiples of 3 and 5 - by bitm0de - 12-08-2016, 05:35 PM