Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions how to check and print the no of times an integer is repeated in an array
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vikas
how to check and print the no of times an integer is repeated in an array
1 Answer(s)      3 years and 10 months ago
Posted in : Java Interview Questions


how to check and print the no of times an integer is repeated in an array???

suppose my input is 2 4 2 5 2 4 3 4 5 2 then my output should be

2-4 times 4-3 times 5-2 times 3-1 times


Advertisement
View Answers

January 7, 2011 at 12:07 PM


Hi Friend,

Try the following code:

import java.util.*;

class  CountNumberOccurrence {
  public static void main(String[] args) throws Exception{
  int array[]={2,4,2,5,2,4,3,4,5,2};
  for(int counter =0;counter<array.length;counter++){
  int n= array[counter];
  int count=0;
  for ( int i=0; i<array.length; i++){
  if (n==array[i])
  count++;
}
boolean flag=false;
for(int j=counter-1;j>=0;j--){
if(n==array[j])
flag=true;
}
if(!flag){
System.out.println(n+" - "+count+" times ");
}
}
}
}

Thanks



Related Tutorials/Questions & Answers:
how to check and print the no of times an integer is repeated in an array
how to check and print the no of times an integer is repeated in an array  how to check and print the no of times an integer is repeated in an array??? suppose my input is 2 4 2 5 2 4 3 4 5 2 then my output should be 2-4
How can print integer in method
How can print integer in method   a method call process public process(int jobid,int remain){ } how to print int jobid ,int remain in for loop jobid in proc[0],remain in proc[1],both show in text file how to print proc[0
Advertisements
How to Print Array in JavaScript
How to Print Array in JavaScript In this section you will learn about Array in JavaScript. Array are important part of all programming languages. Array...;<h2>Click to print the array element</h2></p><p><input
Java Reverse integer array
Java Reverse integer array In this tutorial, you will learn how to reverse integer array. Here, we have created a method to reverse an array which has been passed as a parameter and returns a new array with all the elements in reverse
How to Remove Repeated Characters from the String?
How to Remove Repeated Characters from the String?  Hi, I trying to develop an application which will remove the repeated characters from... the example of how to remove repeated characters from the string. Please visit
Reverse integer array program
Reverse integer array program  Been tasked with the following question: Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8
How to put text file numbers to array and check the position of numbers?
How to put text file numbers to array and check the position of numbers?   I have numbers in text file data.txt 12 9 8 3 1
how i can print the elements before a spicific value in array queue?
how i can print the elements before a spicific value in array queue?  how i can printall elements befor the spicific value and print this value also   Hi Friend, Try this: <html> <script> var arr=new Array
print array in following format
print array in following format  i want print two array in following format first array= 1,2,3,4,5,6,7,8,9 second array=11,12,13,14,15,16,17,18,19 i...; Here is a code that displays the array values in the following pattern: 1 2
Simplest way to print an array in Java
Simplest way to print an array in Java  Simplest way to print an array in Java
how to print the average of each column of 2d n*m array using java
how to print the average of each column of 2d n*m array using java  here is my code: import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
how to print the server time
how to print the server time  how to print the server time in jsp and update time in fix interval
How to print this Format exactly?
How to print this Format exactly?   * * * & reverse
How to print this in java?
How to print pattern in Java?  How to print a particular pattern in Java...;  How to print this in java
how to print the server time
how to print the server time  i want to print database time in clintside and update time in every secound without creating connection to database for each time. how can i do
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
How to check a checkbox - Struts
How to check a checkbox  Hello Community, How can i check a checkbox defined with tags. with plain html, the tag checks the box. with the other tags i am getting an error that the property "checked" is not defined. Can someone
JavaScript array print
JavaScript array print     ... print them wherever we wish. Here is the simple example of array printing which... have used a for loop to print all the elements of the array. for(var i
How does Java handle integer overflows and underflows?
How does Java handle integer overflows and underflows?   hi, How does Java handle integer overflows and underflows? Thanks
how to print - Java Beginners
how to print  how to print something on console without using System.out.print() method ?  Hi Friend, You can use PrintWriter to write anything on the console. import java.io.*; public class Print{ public static
how to print the following pattern
how to print the following pattern  Hello hEllo heLlo helLo hellO pls reply soon its an emergency   class StringPattern { public static void main(String[] args) { String st="hello
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list /attendence in pdf format. please help me. thanks in advance.   Here
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo C  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
How to design a foot print on the sand, print on the sand, print
How to design a foot print on the sand       You might have seen foot prints on the sand field. Do you think, it can be design in the photoshop, yes I have done here. I have used
How to Print a Stack Trace Message
How to Print a Stack Trace Message  Debugging of Java program requires... times you have to print the detailed error message on the console... (Exception e){    e.printStackTrace(); } Check how to use
count the repeated character in one string
count the repeated character in one string  to find the how character... 'a 'was repeated )   Hi Friend, Try the following code: import...; } if(!flag){ System.out.println("Character :"+ch+" occurs "+count+" times
display repeated lines in a file
display repeated lines in a file  i want a java program that accepts file from user and displays the repeated lines in a file
Create array of random size
Create array of random size In this tutorial, you will learn how to create a randomly sized integer array. For this, we have declared an array and using the Random class, we have set the random size to array. We have stored
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi... times like get the last modified file bet 02:00:00am and 01:00:00am (so... Thank you  Hi Friend, Check this: import java.io.*; import
 

 

 

DMCA.com