Displaying Numbers

This displays numbers from 0 to 25...i was wondering what i could use to not display numbers 10 through 15...which means i want to display numbers from 0 to 25 except numbers from 10 to 15.....any help


static
void Main()

{

for(int j = 0; j<26; j++)

Console.WriteLine("Number {0}", j);

Console.WriteLine("Press enter to continue");

Console.ReadLine();

}

}




Answer this question

Displaying Numbers

  • yanivoroz

    using System;

    class Math

    {

    static void Main()

    {

    for (int j = 0; j < 26; j++)

    {

    if (!(j >= 10 && j <= 15))

    {

    Console.WriteLine("Number {0}", j);

    Console.WriteLine("Press enter to continue");

    Console.ReadLine();

    }

    }

    }

    }

    this gives an output of Number 0.......



  • pena_a

    Oops that one should be:

    int[] values = {1,2,3,4,5,6,7,8,9,15,16,17,18,19,20,21,22,23,24,25};

    foreach(int count in values)

    {

            Console.WriteLine("Number {0}", count);

    }

    Console.WriteLine("Press enter to continue");

    Console.ReadLine();

     



  • Whitey

    How about this one Smile


    int[] values = {1,2,3,4,5,6,7,8,9,15,16,17,18,19,20,21,22,23,24,25};

    foreach(int count in values)

    {

       if(count < 10 || count > 15)

       {

          Console.WriteLine("Number {0}", count);

       }

    }

    Console.WriteLine("Press enter to continue");

    Console.ReadLine();


     



  • CSFDeveloper

    Thanks Vikram i knew you was a geniusBig Smile

  • tirengarfio

    Hi Dpowers,

    Use a if statement:


    for (int j = 0; j < 26; j++)

    {

    if (!(j >= 10 && j <= 15))

    {

    Console.WriteLine("Number {0}", j);

    Console.WriteLine("Press enter to continue");

    Console.ReadLine();

    }

    }


     


    Regards,
    Vikram



  • Brent-GPTX

    Hi Dpowers ,

        Maybe my solution looks like previous posted message.But it will be beneficial for you.(usage of "if" statement).

    static void Main(string[] args)
    {
          
               for(int count = 0;count <26; count ++)
                {
                    if(count < 10 || count > 15)
                    {                       
                        Console.WriteLine("Number {0}", count);
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                    }
                  
               
                }
    }
                                                                                                 Cheers =)
       
    Marie


  • ramos_490

    Alright i think i uderstand but when i compile the code i get Number 10; see check it out...thanks for the help too

    static void Main()

    {

    for (int j = 0; j < 26; j++)

    {

    if ((j >= 10 && j <= 15))

    {

    Console.WriteLine("Number {0}", j);

    Console.WriteLine("Press enter to continue");

    Console.ReadLine();

    }

    }

    }

    }



  • Bochur

    Thats correct, you would need to hit a key after the display of each number. If you want all the numbers to be displayed before it prompts you to press a key, then u need to use the following code below:


    for (int j = 0; j < 26; j++)

    {

    if (!(j >= 10 && j <= 15))

    {

    Console.WriteLine("Number {0}", j);

    }

    }

    Console.WriteLine("Press enter to continue");

    Console.ReadLine();


     



    Regards,
    Vikram



  • JohnDaldry

    Hi Dpowers,

    You did not notice the Not Operator(!) in my code
    See the if statement in detail once again: if ( ! (j >= 10 && j <= 15))

    I have made the ! operator big in size now. In fact if you had copy-pasted the earlier code it would have worked.

    Regards,
    Vikram


  • ZhuangYicheng

    Well i had the not operator in but the result was Number 0...I removed it and i got Number 10 as the output


  • Displaying Numbers