Whats wrong in this c# code?

Discussion in 'General Computer Support' started by Ravino, Aug 3, 2008.

  1. Ravino

    Ravino

    Joined:
    Aug 3, 2008
    Messages:
    1
    Location:
    INDIA
    The compiler says arrays out of bounds exception

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace PigLatin_Game
    {
        class Program
        {
            static void Main(string[] args)
                {
                    Console.WriteLine("Enter the String");
                    String str;
                    Char ch;
                    String str2="";
                    int i,j=0;
                     int[] f={0,0,0,0,0,0,0,0,0,0};
                    String[] str1 = new String[5];
                    str=Console.ReadLine();
                    str1=str.Split(' ');
                    for (int y = 1; y < str1.Length; y++)
                    {
                        foreach (String x in str1)
                        {
                            if (f[j]==0)
                            {
                                if ((x.StartsWith("a")) || (x.StartsWith("e")) || (x.StartsWith("i")) || (x.StartsWith("o")) || (x.StartsWith("u")))
                                {
                                    str2 = string.Concat(x, "ay");
                                    f[j] = 1;
                                }
                                else
                                {
                                    ch = x[0];
                                    //if (ch.Equals('a' || 'e' || 'i'))
                                    //{
                                    //    Console.WriteLine("vowel");
                                    //    f = 1;
                                    //}
                                    str2 = x.Remove(0, 1);
                                    str2 = string.Concat(str2, ch);
                                    if ((str2.StartsWith("a")) || (str2.StartsWith("e")) || (str2.StartsWith("i")) || (str2.StartsWith("o")) || (str2.StartsWith("u")))
                                        str2 = string.Concat(str2, "ay");
                                }
                            }
                           [QUOTE]str1[j] = str2;[/QUOTE] 
                            j++;
    
                        }
                    }
               
    
    
                Console.WriteLine("\nThe separated string is:  ");
                foreach (String x in str1)
                {
                    Console.WriteLine(x);
                }
                Console.ReadLine();
            }
        }
    }
    
    Ravino, Aug 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2lt?=

    I don't know whats wrong!!!

    =?Utf-8?B?S2lt?=, Sep 7, 2005, in forum: Wireless Networking
    Replies:
    2
    Views:
    599
    =?Utf-8?B?S2lt?=
    Sep 8, 2005
  2. =?Utf-8?B?S2ViaXNob3AzMQ==?=

    Whats wrong with .net passport and IE

    =?Utf-8?B?S2ViaXNob3AzMQ==?=, Oct 14, 2004, in forum: MCSE
    Replies:
    2
    Views:
    733
    Consultant
    Oct 14, 2004
  3. Jason
    Replies:
    5
    Views:
    958
    Barry Margolin
    Mar 10, 2006
  4. Howard Huntley

    Whats Wrong With This Router

    Howard Huntley, Mar 31, 2006, in forum: Cisco
    Replies:
    2
    Views:
    1,210
    Howard Huntley
    Apr 10, 2006
  5. °Mike°

    whats wrong brian

    °Mike°, Jul 27, 2004, in forum: Computer Support
    Replies:
    34
    Views:
    987
    @}-}-------Rosee
    Jul 31, 2004
Loading...

Share This Page