I m not able to crack UEFA championship problem via this code.why?
import java.util.*;
class teamInfo {
String teamName;
int score,goalDifference;
teamInfo(String teamName,int score,int goalDifference){
this.teamName=teamName;
this.score = score;
this.goalDifference=goalDifference;
}
void display(){
System.out.println(teamName);
System.out.println(score);
System.out.println(goalDifference);
}
}
public class Main
{
public static void main(String[] args) {
try{
int z=-1,x=-1,s=0;
int score_t1=0,score_t2=0,t1_score,t2_score;
String t1,t2;
teamInfo[] teams = new teamInfo[4];
String[] str= new String[5];
str[0]=str[1]=str[2]=str[3]="";
int temp;
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int m=1;m<=t;m++){
z=-1;x=-1;
for(int j=1;j<=12;j++){
t1 = sc.next();
t1_score = sc.nextInt();
t2 = sc.next();
t2_score = sc.nextInt();
t2 = sc.next();
if(t1_score>t2_score){
score_t1=3;
score_t2=0;
}
else if (t1_score<t2_score) {
score_t1=0;
score_t2=3;
}else{
score_t2=1;score_t1=1;
}
for(int k=0;k<=z;k++){
x=-1;
if(teams[k].teamName.equals(t1)){
x=k;
break;
}
}
if (x==-1){
z++;
teams[z]= new teamInfo(t1,score_t1,t1_score-t2_score);
}
else{
teams[x].score+=score_t1;
teams[x].goalDifference+=t1_score-t2_score;
}
for(int k=0;k<=z;k++){
x=-1;
if(teams[k].teamName.equals(t2)){
x=k;
break;
}
}
if (x==-1){
z++;
teams[z]= new teamInfo(t2,score_t2,t2_score-t1_score);
}
else{
teams[x].score+=score_t2;
teams[x].goalDifference+=t2_score-t1_score;
}
}
for(int a=0;a<2;a++){
temp=a;
for(int k=a+1;k<4;k++){
if(teams[a].score<teams[k].score){
temp=k;
}
else if((teams[a].score==teams[k].score) && (teams[a].goalDifference<teams[k].goalDifference)){
temp=k;
}
}
str[s]=teams[temp].teamName;
s++;
teams[temp].score=-1;
}
teams[0]=teams[1]=teams[2]=teams[3]=null;
}
System.out.println(str[0]+" "+str[1]);
System.out.println(str[2]+" "+str[3]);
}catch(Exception e){
return;
}
}
}