### Source code for ValidateStringLengthExample.java:

>     public class ValidateStringLengthExample
>     {
>     	public static final int VALID     = 0;
>     	public static final int TOO_SHORT = 1;
>     	public static final int TOO_LONG  = 2;

>     	public int validateStringLength(String inputString)
>     	{
>     		int min = 10;	// minimum valid String length
>     		int max = 15;	// maximum valid String length
>     		if(inputString.length() < min)
>     		{
>     			return(TOO_SHORT);
>     		}
>     		if(inputString.length() > max)
>     		{
>     			return(TOO_LONG);
>     		}
>     		return(VALID);
>     	}

>     	public void testExamples()
>     	{
>     		int ret = validateStringLength("some input text here");
>     		if(ret == TOO_SHORT)
>     		{
>     			System.err.println("The input length is too short");
>     		}
>     		else
>     		{
>     			// continue with program flow
>     			System.err.println("The input length is not too short");
>     		}
>     		if(ret != VALID)
>     		{
>     			// Perhaps check for more specific error type here.
>     			System.err.println("The input length is not valid");
>     		}
>     	}

>     	public static void main(String args[])
>     	{
>     		ValidateStringLengthExample ex = new ValidateStringLengthExample();
>     		ex.testExamples();
>     	}
>     }

### Output from ValidateStringLengthExample.java:

    The input length is not too short
    The input length is not valid

--- Output Ends ---

#### NOTE:

You are reading previously generated output. You are not currently running the ValidateStringLengthExample application at the momement. You need to compile and run the source code first.

#### To run this program:

`
- javac ValidateStringLengthExample.java
- java ValidateStringLengthExample
`

Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR