- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
If a number is read as a String, how to Count the no of times the highest number repeated in the string?n a. Ex: 2 4 3 4 2 4 0 -> (3)
To do so,
- Trim the given string and split it using the split() method (Removing the empty spaces in-between).
- Create an integer array and in loop convert each element of the string array to an integer using Integer.parseInt() method and assign it to the respective element of the integer array.
- Sort the obtained integer array, since this method sorts the elements of the array in ascending order the last element will be the maximum of the array.
- Create an integer variable count with initial value 0.
- Compare each element of the array with the maximum value, each time a match occurs increment the count.
- The final value of the count will be the required result.
Example
import java.util.Arrays; public class CountingHighestNumber { public static void main(String args[]) { int count = 0; String str = "2 3 4 3 8 8 3 5 2 6 8"; String[] strArray = str.trim().split(" "); int size = strArray.length; int[] intArray = new int[size]; for(int i = 0; i<size; i++) { intArray[i] = Integer.parseInt(strArray[i]); } System.out.println("Integer Array ::"+Arrays.toString(intArray)); Arrays.sort(intArray); System.out.println("sorted Array ::"+Arrays.toString(intArray)); int max = intArray[size-1]; System.out.println("Max value is :"+max); for(int i = 0; i<size; i++) { if(intArray[i]==max) { count++; } } System.out.println("Number of times the largest value repeated is ::"+count); } }
Output
Integer Array ::[2, 3, 4, 3, 8, 8, 3, 5, 2, 6, 8] sorted Array ::[2, 2, 3, 3, 3, 4, 5, 6, 8, 8, 8] Max value is :8 Number of times the largest value repeated is ::3
- Related Articles
- If a number is read as a String, how to Count the no of times the highest number repeated in the string? a. Ex: 2 4 3 4 2 4 0 -> (3)
- Simplify and express each of the following in exponential form:$(i)$. $frac{2^3times3^4times4}{3times32}$$(ii)$. $[(5^2)^{3 }times5^4]div5^7$$(iii)$. $(25^4div5^3)$$(iv)$. $frac{3times7^2times11^8}{21times11^3}$$(v)$. $frac{3^7}{3^4times3^3}$$(vi)$. $2^0+3^0+4^0$$(viii)$. $2^0times3^0times4^0$$(viii)$. $(3^0+2^0)times5^0$$(ix)$. $frac{2^8times a^5}{4^3times a3}$$(x)$. $(frac{a^5}{a^3})times a^8$$(xi)$. $frac{4^5times a^8b^3}{4^5times a^5b^2}$$(xii)$. $(2^3times2)^2$
- Following data gives the number of children in 41 families:$1, 2, 6, 5, 1, 5, 1, 3, 2, 6, 2, 3, 4, 2, 0, 0, 4, 4, 3, 2, 2, 0, 0, 1, 2, 2, 4, 3, 2, 1, 0, 5, 1, 2, 4, 3, 4, 1, 6, 2, 2.$Represent it in the form of a frequency distribution.
- Observe the following pattern( (1 times 2)+(2 times 3)=frac{2 times 3 times 4}{3} )( (1 times 2)+(2 times 3)+(3 times 4)=frac{3 times 4 times 5}{3} )( (1 times 2)+(2 times 3)+(3 times 4)+(4 times 5)=frac{4 times 5 times 6}{3} )and find the value of( (1 times 2)+(2 times 3)+(3 times 4)+(4 times 5)+(5 times 6) )
- Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. in C++
- Choose the correct answer from the given four options in the following questions:Which of the following equations has no real roots?(A) ( x^{2}-4 x+3 sqrt{2}=0 )(B) ( x^{2}+4 x-3 sqrt{2}=0 )(C) ( x^{2}-4 x-3 sqrt{2}=0 )(D) ( 3 x^{2}+4 sqrt{3} x+4=0 )
- Simplify the following:$3^0 + (-4)^{-1} times 2^2$.
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Find the number from each of the following expanded forms:$(a)$. $8times10^4+6times10^3+0times10^2+4times10^1+5times10^0$$(b)$. $4times10^4+5times10^3+3times10^2+2times10^0$$(c)$. $3times10^4+7times10^2+5times10^0$$(d)$. $9times10^5+2times10^2+3times10^1$
- Prove that the points $(-4, -1), (-2, -4), (4, 0)$ and $(2, 3)$ are the vertices of a rectangle.
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Evaluate: $frac{a^{2 n+1} times a^{(2 n+1)(2 n-1)}}{a^{n(4 n-1)}times(a^{2})^{2 n+3}}$.
- The value of ( frac{left((243)^{1 / 5}right)^{4}}{left((32)^{1 / 5}right)^{4}}=? )A. ( quad frac{3}{2} )B. ( left(frac{3}{2}right)^{-4} )C. ( frac{1}{2^{-4} times 3^{-4}} )D. ( frac{1}{2^{4} times 3^{-4}} )
- Show that the points $(-4, -1), (-2, -4), (4, 0)$ and $(2, 3)$ are the vertices points of a rectangle.

Advertisements