+ 2
count the no. of times a series of same no. occurs in the array.Also print the numbers occuring together
{10,20,20,30,32,32,32,34} output- count:2 no.-20,32,
1 Respuesta
+ 12
public class Program
{
public static void main(String[] args) {
int c = 0, count = 0;
int [] array1 = {10,20,20,30,32,32,32,34};
for(int i = 0; i < array1.length; i += count)
{
count = 0;
for(int j = i + 1; j < array1.length; j++)
{
if(array1[i] == array1[j])
{
++count;
}
}
if(count > 0)
{
System.out.println(array1[i]);
++c;
}
else ++count;
}
System.out.println(c);
}
}