Problème de résultat érroné
Bonjour,
J'ai écrit ce programme qui doit résoudre un problème mais le résultat est faux
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| 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 résultat:
Citation:
====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 ne peux entrer que les températures que pour 2 cities.
Quelqu'un saurait-il me dire pourquoi la 3ème cities ne s'affiche pas ?
Merci d'avance pour votre aide.