This is my code:
public class part {
public static void main(String args[]){
int []timea={1,2,3,4,5,6};
int [] timeb={3};
int k1=0,k2=0;
while(k1<timea.length && k2<timeb.length) {
if (timea[k1] < timeb[k2]) {
System.out.println("Timeb is big");
k1++;
} else if (timea[k1] == timeb[k2]) {
System.out.println("We are same");
k2++;
} else if (timea[k1] > timeb[k2]) {
System.out.println("Timea is big");
k1++;
}
}
}
}
Output:
Timeb is big
Timeb is big
We are same
My problem is that Timea is big never printed. But as per my logic
else if (timea[k1] > timeb[k2]) {
System.out.println("Timea is big");
k1++;
}
This code block is executed when it get {4,5,6} but I cannot understand why this portion not executed? Is there any logical error in my code block?
Aucun commentaire:
Enregistrer un commentaire