I'm new to java and im trying to write a program that gets an undefined amount of integers and tells you the longest order of the same integer.
public class Search{
public static void main(String args[]){
int order[] = new int[args.length];
for(int i = 0;i < args.length;i++){ //Input into array
order[i] = Integer.parseInt(args[i]);
}
int count = 0;
int temp_count = 0;
int pos = -1;
int temp_pos = -1;
boolean search = false;
for(int i = 1; i < args.length;i++){
if(order[i-1] != order[i]){
temp_count = 1; //line of the same integers?
search = true;
temp_pos++;
} else if(search && order[i-1] == order[i]){ // How long is the line?
temp_count++;
} else if(search && order[i-1] != order[i]){ // Does the line end?
if (temp_count > count){
count = temp_count; // Update old length and position
pos = temp_pos;
}
search = false;
}
}
System.out.println("length: " + count); //output
System.out.println("position " + pos);
}
}
The output is 0 and -1 , what should only be the case if there is no order of the same integers.