tenho um vector com os seguintes dados como exemplo:
porto 1 2 3 4 5 6 7 8
viseu 7 8 9 7 4 3 9 6
evora 1 2 3 4 5 6 2 3
preciso de somar os valor da coluna 4 ate a coluna 8 percorrendo as linhas.e preciso de guardar os valore somados num vector para determinar o maior. tenho o seguinte codigo:
publicstaticvoidmain(String[]args){Scannerentrada=newScanner(System.in);intmenu,input,i,j,soma,soma1,max,max1,maior,maior1,pos;Strings;Stringtexto[]=newString[18];intmat[][]=newint[18][10];intvecAux[]=newint[10];intvec1[]=newint[10];intlinhas=0,x,y,z,colunas,l;intk=0;Stringlinha;do{System.out.println("\n1-carregar distrito\n2- ver dados\n3-distrito com mais votos\n4-numero de votos do partido vencedor\n5-partido que ganhou em cada distrito\n0-exit");System.out.println("introduza a opçao k deseja");menu=entrada.nextInt();switch(menu){case1:JFileChooserfich=newJFileChooser();input=fich.showOpenDialog(null);if(input==JFileChooser.APPROVE_OPTION){try{Scannerler=newScanner(fich.getSelectedFile());while(ler.hasNext()){s=ler.nextLine();System.out.print(s);Stringvec[]=s.split("\\|");for(i=0;i<vec.length;i++){if(i==0){texto[k]=vec[i];}else{mat[k][i-1]=Integer.parseInt(vec[i]);}}k++;}}catch(FileNotFoundExceptionex){ex.printStackTrace();}}else{System.out.println("nao escolheu ficheiro");}break;case2:for(x=0;x<k;x++){linha=texto[x]+"\t";soma=0;for(y=0;y<=7;y++){linha+=mat[x][y]+"\t";soma=soma+mat[x][y];}System.out.print("\n"+linha+" "+soma);}break;case3:maior=mat[0][9];for(x=0;x<k;x++){if(mat[x][9]>maior){maior=mat[x][9];}}System.out.println(" o distrito com maior numero de votos foi:"+texto[maior]);break;case4:maior=vecAux[0];for(y=3;y<8;y++){soma=0;for(x=0;x<=(k+1);x++){soma=soma+mat[x][y];vecAux[x]=soma;if(vecAux[1]>maior){maior=vecAux[1];}}}System.out.println("o partido que ganhou teve um total de:"+maior);break;case5:maior=vec1[0];for(x=0;x<k;x++){soma=0;for(y=1;y<3;y++){soma=soma+mat[x][y];vec1[x]=soma;for(x=1;x<=2;x++){if(vec1[x]>maior){maior=vec1[x];}}}//System.out.print(" "+soma);}System.out.println(texto[maior]);case0:try{Formattersaida=newFormatter(newFile("distritos.txt"));for(x=0;x<k;x++){linha=texto[x]+"\t";for(y=0;y<8;y++){linha+=mat[x][y]+"\t";}saida.format("%n%s",linha);}saida.close();}catch(FileNotFoundExceptionex){ex.printStackTrace();}break;}}while(menu!=0);}