I got a problem in hand where I can't find any solution yet.. I don't know how to explain this properly let me begin with some sample input outputs
Input: {1,1,2,3,3} => Output will be: 2
Input: {1,1,1,1,1} => Output will be: 1
Input: {1,2,1,1,1} => Output will be: 1
Input: {1,1,2,1,1,2,4,4} => Output will be: 3
So the thing is it will basically out put how many group of 2 or more same consecutive numbers in a series. I hope I'm not speaking gibberish :x:.
my code is incomplete/wrong.:(-:
Code:
import javax.swing.JOptionPane;
public class Cluster {
public static void main(String[] args) {
// TODO Auto-generated method stub
String a= JOptionPane.showInputDialog("Enter Array size" );
int size= Integer.parseInt(a);
int [] array = new int[size];
for(int i=0; i<size; i++){
a= JOptionPane.showInputDialog("Enter array elements" );
int n= Integer.parseInt(a);
array[i]=n;
System.out.print(" "+array[i]);
}
int flag=0;
for (int j=0; j<size-1; j++){
if (array[j]!=array[j+1]){
flag=flag+1;
if(array[j+1]!=array[j+2]){
}
}
} System.out.println(" Clusters "+flag);
}
}

