Java:le résultat fausse

Résolu
domxaline -  
 domxaline -
Bonjour,
j'ai écrit ce pb,mais le résultat est fausse
import java.io.*; 
public class CityTemp  
{ 
 public static void main(String []args) 
 { 
  String str; 
  double temp[][]=new double [11][32]; 
  double HighestCityTemp[]=new double [11]; 
  double LowestCityTemp[]=new double [11]; 
   
  HighestCityTemp[0]=0.0; 
  LowestCityTemp[0]=0.0; 
   
  try 
  { 
   BufferedReader obj= new BufferedReader(new InputStreamReader(System.in)); 
   System.out.println("\n====Finding Top 3 cities higest and lowest temperature====\n\n"); 
   for(int i=1; i<3; i++) 
   { 
    System.out.println("\n\nCITY :"+i); 
    for(int j=1; j<=3; j++) 
    { 
     System.out.println("Temperature on day:"+j+"For city :"+i+ "is :"); 
     System.out.flush(); 
     str=obj.readLine(); 
     temp[i][j]=Double.parseDouble(str); 
     if(j==1)// intialization 
     { 
      HighestCityTemp[i]=temp[i][j]; 
      LowestCityTemp[i]=temp[i][j];  
     } 
     if(temp[i][j]>HighestCityTemp[i]) 
     { 
      HighestCityTemp[i]=temp[i][j]; 
     } 
     if(temp[i][j]<LowestCityTemp[i]) 
     { 
      LowestCityTemp[i]=temp[i][j]; 
     } 
    } 
   } 
  } 
  catch(Exception e) 
  {} 
  for(int i=1; i<=3; i++) 
  { 
   System.out.println("\n\nHIGHEST TEMPERATURE FOR CITY"+i+"is"+HighestCityTemp[i]); 
   System.out.println("LOWEST TEMPERATURE FOR CITY"+i+"is"+LowestCityTemp[i]); 
   System.out.println(""); 
  } 
 } 

} 

le resultat
====Finding Top 3 cities higest and lowest temperature====

CITY :1
Temperature on day:1For city :1is :
12
Temperature on day:2For city :1is :
13
Temperature on day:3For city :1is :
14


CITY :2
Temperature on day:1For city :2is :
15
Temperature on day:2For city :2is :
16
Temperature on day:3For city :2is :
17


HIGHEST TEMPERATURE FOR CITY1is14.0
LOWEST TEMPERATURE FOR CITY1is12.0



HIGHEST TEMPERATURE FOR CITY2is17.0
LOWEST TEMPERATURE FOR CITY2is15.0



HIGHEST TEMPERATURE FOR CITY3is0.0
LOWEST TEMPERATURE FOR CITY3is0.0

je peux entrer que les temperature de 2 cities
pourquoi 3eme cities s'affiche pas?
aidez moi svp

A voir également:

2 réponses

Utilisateur anonyme
 
Salut,

Tu n'as sans doute pas cherché beaucoup !

Première boucle pour les City 1 2 et 3:
for(int i=1; i<4; i++) // <<<<<<<<<<<<


Deuxième boucle pour les jours 1 2 et 3 de chaque City:
for(int j=1; j<4; j++) // <<<<<<<


Cordialement,

Dan
0
domxaline
 
vous avez raison,j'ai compris mon erreur
0