Programming language-c# input-a3b4 output-aaabbb program bool result; if (b[j] >= 0 && b[j] <= 9) }
Console.WriteLine("enter the string");
string a=Console.ReadLine();
char[] b = a.ToCharArray() ;
for(int i=0;i<=b.Length;i++)
{
result = char.IsLetter(b[i]);
if (result == true)
{
char c = b[i];
int count = 0;
for (int j = i + 1; j <= b.Length; j++)
{
{
count = (count * 10) + b[j];
}
}
for (int k = 0; i <= count; k++)
{
Console.Write(c);
}
}
You need to make the following changes in your code.
i<b.Length
and j<b.Length
because the array b is of length 4 with its first and last elements as b[0] and b[3] respectively.k<count
(int)Char.GetNumericValue(b[j])
.The problem statement for your program is not clear but the program runs fine on doing the above changes. I am writing the program again with the changes included.
using System;
public class Test
{
public static void Main()
{
bool result;
Console.WriteLine("enter the string");
string a=Console.ReadLine();
char[] b = a.ToCharArray() ;
for(int i=0;i<b.Length;i++)
{
result = char.IsLetter(b[i]);
if (result == true)
{
char c = b[i];
int count = 0;
for (int j = i + 1; j < b.Length; j++)
{
if ((int)Char.GetNumericValue(b[j]) >= 0 && (int)Char.GetNumericValue(b[j]) <= 9)
{
int d = (int)Char.GetNumericValue(b[j]);
count = (count * 10) + d;
}
}
for (int k = 0; k < count; k++)
{
Console.Write(c);
}
}
}
}
}
You can state your problem statement as well if you want to get the correct output.