Programming and Computer Science in Java:
Class Notes:  Tue, Feb 11, 2003
    David Kosbie, 2002-2003

See Course Home Page

See lab1.doc for today's notes.

Full class notes coming soon....  For now, here is the readInt() code for use in this lab:

	// readInt()
	// Include this method if you call readInt() in your code.	
	// You may copy this code from the course web site.
	public static int readInt()
	{
		int result, sign, c;
		result = 0;
		sign = 1;
		try
		{
			// skip non-integer characters
			while (true)
			{
				c = System.in.read();
				if ((c >= '0') && (c <= '9'))
					break;
				if (c == '-')
					sign = -sign;
			}
			// now read digits
			while (true)
			{
				result = 10 * result + (c - '0');
				c = System.in.read();
				if ((c < '0') || (c > '9'))
					break;
			}
		}
		catch (java.io.IOException e)
		{
			System.out.println("Error while reading integer.");
		}
		return result * sign;
	}

 

See Course Home Page