A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE
Answer Posted / rohit tehlan
using System;
using System.Linq;
namespace StringHighestCharacterOccur
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the character string ");
string str = Console.ReadLine();
int[] max = new int[str.Length]; // this will store occurence count for each character
for (int i = 0; i < str.Length; i++)
{
int count = 0;
for (int j = 0; j < str.Length; j++)
{
if (str[i] == str[j])
{
count++;
}
}
max[i] = count;
}
int maxvalue = max.Max();
int maxvalueindex = max.ToList().IndexOf(maxvalue); // this will give the index of character with max occurence
Console.WriteLine("Character with max occurence is: " + str[maxvalueindex]);
Console.ReadLine();
}
}
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
what is the certificates in biztalk?
In an customer exit (include Z) program, only the last record is getting fetched. The exit is getting called after pressing save button. What to write for fetching the first record ? Before saved to a SAP table how can i call all these records in an itab in the exit ?
public static void main(String args[]) describe it
Need provab technical test questions
Mainly Related to Oracle, DBMS , Oracle Stored Procedures, Functions, Oracle 9i Architecture, Redo logs..., Views,
where is available in this mantis toturials?
how much fee for deccan soft institute .how to block seat for sandeep sir class reply soonnnnÂ
difference between mantis and other tools?
Explain with examples any 2 features of OOPS.
what is programmable BIST in today ic design
5.Call by value and Call by reference with program?
Write a shell program to test whether a given year is leap year or not ?
Hi all... I had completed MSC(Computer) and had join the construction company based on sap.they want me to work on abap.but software company is totally different from construction company and they want me 2 grasp it as fast i can.i am finding it difficult.what should i do??????
Hi can you please help for the following. I have a ASP.Net web page I want to print the whole page how is it possible? I want It in ASP also.Please send me the solutions dipankar.hazari@gmail.com . Thanks in advance.
what is the system development cycle