basically i have created a program which reads integers from a txt file and works out the averages etc. now the below code i wrote to simply state which month has the highest or lowest rainfall. below i have created the code but on compiling says there an error....can someone spot it and tell me where i have gone wrong? thank you
.............................................................................

double min = store.get(0);
		for(int i=1; i <12; i++){
		if(store.get(i)> min);
		min=store.get(i);
		
		}
		System.out.println("The Minimum Monthly Rainfall is"  + min);
		
		double max = store.get(0);
		for(int i=1; i <12; i++){
		if(store.get(i)< max);
		max=store.get(i);
		}
		System.out.println("The Maximum Monthly Rainfall is"  + max);
	}

Recommended Answers

All 2 Replies

Lines 3 and 11. No semicolons after if statements.

Grn Xtrm is right. Remove the semi-colons.

Also, check this:

import	java.util.*;

class minmax
{
	public static void main(String[] args)
	{
		//assuming the "store" is a Vector of Doubles
		Vector<Double> store = new Vector<Double>();
		//
		store.add((double)8);
		store.add((double)3);
		store.add((double)7);
		store.add((double)9);
		//
		double dblMin = store.get(0);
		double dblMax = dblMin;

		//Do both checks at the same time
		for(double dbl : store)
		{
			if(dblMin > dbl)
			{
				dblMin = dbl;
			}

			if(dblMax < dbl)
			{
				dblMax = dbl;
			}
		}
		//
		System.out.println("The minimum monthly rainfall is " + dblMin +
			"\nThe maximum monthly rainfall is " + dblMax);
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.