try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the continent;");
String CN = in.readLine();
String MaxDate="1";
for(Earthquakerecd e : eqList)
{
if( e.getContinent().equals("CN"))
{
MaxDate=e.getDate();
}
{
System.out.println( e.toString());
}
}
System.out.println( MaxDate);
}
catch (IOException e)
{
System.out.println("IOException has been caught");
}
This is a simple problem i think. In this problem Maxdate is declared as 1. CN is a string for continent . If the user input matches the continent , then the date should be passed from e.getDate() to Maxdate. In anycase , we should never get the output as 1 , it should be some date from object e. I am always getting 1 for Maxdate. Any possible solutions? is my syntax right?
Seems like you want:
Right now you are comparing against the String literal “CN”. You aren’t using the variable
CNfor anything.I’m assuming you meant to insert an
elseafter yourifstatement?Also, in Java it’s common to not start your variable names with uppercase letters (name your string
cninstead ofCN).