using System;
namespace Console_JaggedArray
{
class JaggedArray
{
public void JA()
{
//Declaring the jagged array to accept the input from user
int i;
string[][] jag = new string[3][];
//To enter 1st set of column by user
Console.Write("Enter the 1st set of columns :");
int s = int.Parse(Console.ReadLine());
jag[0] = new string[s];
for (i = 0; i < s; i++)
{
jag[0][i] = Console.ReadLine();
}
Console.WriteLine("\n");
//To enter 2nd set of column by user
Console.Write("Enter the 2nd set of columns :");
int s1 = int.Parse(Console.ReadLine());
jag[1] = new string[s1];
for (i = 0; i < s1; i++)
{
jag[1][i] = Console.ReadLine();
}
Console.WriteLine("\n");
//To enter 3rd set of column by user
Console.Write("Enter the 3rd set of columns :");
int s2 = int.Parse(Console.ReadLine());
jag[2] = new string[s2];
for (i = 0; i < s2; i++)
{
jag[2][i] = Console.ReadLine();
}
Console.WriteLine("\n");
//For print all columns
Console.WriteLine("\n Print all the Columns :");
Console.WriteLine("1st column");
for (i = 0; i < s; i++)
{
Console.WriteLine(jag[0][i]);
}
Console.WriteLine("\n");
Console.WriteLine("2nd column");
for (i = 0; i < s1; i++)
{
Console.WriteLine(jag[1][i]);
}
Console.WriteLine("\n");
Console.WriteLine("3rd column");
for (i = 0; i < s2; i++)
{
Console.WriteLine(jag[2][i]);
}
Console.WriteLine("\n");
}
static void Main(string[] args)
{
JaggedArray j = new JaggedArray();
j.JA();
Console.ReadKey();
}
}
}
No comments:
Post a Comment