Jump to content

Recommended Posts

Posted

Please ye question he help cheyara...its very urgent...

 

//Alter the code below to change the order of the elements
// in the two arrays in ascending order by the number of vowels
// in each states array entry. Preserve the corresponding entries
// in the capitals array.
//
// The output should appear as follows:
// Austin is the capital of Texas
// Tallahassee is the capital of Florida
// Montgomery is the capital of Alabama
// Sacramento is the capital of California
// Baton Rouge is the capital of Louisiana
//
// Do not change the for-loop. The data must
// be in the correct form in the arrays by the
// time the for-loop is executed.

using System;

namespace Challenge
{
class Challenge
{
public static void Main()
{
string[] states=new string[5]
{
"Alabama","California","Florida",
"Louisiana","Texas"
};

string[] capitals=new string[5]
{
"Montgomery","Sacramento","Tallahassee",
"Baton Rouge","Austin"
};

for(int i=0;i<states.Length;i++)
{
Console.WriteLine(capitals[i] + " is the capital of " + states[i]);
}
}
}
}

Posted

Please ye question he help cheyara...its very urgent...

 

//Alter the code below to change the order of the elements
// in the two arrays in ascending order by the number of vowels
// in each states array entry. Preserve the corresponding entries
// in the capitals array.
//
// The output should appear as follows:
// Austin is the capital of Texas
// Tallahassee is the capital of Florida
// Montgomery is the capital of Alabama
// Sacramento is the capital of California
// Baton Rouge is the capital of Louisiana
//
// Do not change the for-loop. The data must
// be in the correct form in the arrays by the
// time the for-loop is executed.

using System;

namespace Challenge
{
public class Challenge
{
public static void Main()
{
string[] states=new string[5]
{
"Alabama","California","Florida",
"Louisiana","Texas"
};

string[] capitals=new string[5]
{
"Montgomery","Sacramento","Tallahassee",
"Baton Rouge","Austin"
};

for(int i=0;i<states.Length;i++)
{
Console.WriteLine(capitals[i] + " is the capital of " + states[i]);
}
}
}
}

now run it...

Posted
Ila chesanu...any better ideas plz...urgent... *<:(
 
using System;
using System.Linq;
using System.Collections.Generic;
 
public class Program
{
public static void Main()
{
string[] states=new string[5] 
         {
            "Alabama","California","Florida",
            "Louisiana","Texas"
         }; 
         
         string[] capitals=new string[5]
         {
            "Montgomery","Sacramento","Tallahassee",
            "Baton Rouge","Austin"
         };
        
Dictionary<string, int> dict = new Dictionary<string, int>();
 
List<string> lstCapitals = new List<string>();
         for(int i=0;i<states.Length;i++)
         {  
int vowelCount = CountVowels(states[i]);
dict.Add(states[i]+","+capitals[i],vowelCount);
 
         }  
foreach (KeyValuePair<string, int> author in dict.OrderBy(key => key.Value))
{
string[] words = author.Key.Split(',');
// Console.WriteLine("Key: {0}, Value: {1}", author.Key, author.Value);
Console.WriteLine(words[1] + " is the capital of " + words[0]);
}
 
}
public static int CountVowels(string value)
{
    const string vowels = "aeiou";
    return value.Count(chr => vowels.Contains(char.ToLowerInvariant(chr)));
}
}
Posted

You have to change arrays first and keep the original for loop as is, I think

Keep the countvowels method

Change arrays to order by countvowels

States = States.OrderBy(x=>countvowels(x))
Something like this so the original for loop won't be changed

Posted

But i vl loose the arrangement of capitals right if arrange states before loop

Posted

I thought they meant i shouldnt change for loop..for(int i=0....) ye line change cheyakudadhu ani

×
×
  • Create New...