/***************************************************************************
* Anastasios Monachos - anastasiosm@gmail.com
* 
* Compile: javac TelGen.java
*
* Usage: java TelGen prefix_code postfix_length 
* 
* This program can be used to generate telephone/fax/mobile numbers.
* Basically, it takes for input two integers. The first one can be
* the country code (eg 0044 for UK), or a country telco operator's
* id number (eg for 004478 for Vodafone, UK), or a specific area's
* code within a country (eg 0044161 for Manchester, UK).
* The second parameter designates the postfix length. If for example
* one enter for prefix_code 0044161 and for postfix_length 7 this
* will generate all numbers between 00441610000000 to 00441619999999.
***************************************************************************/
import java.lang.*;

public class TelGen
{
public static void main(String args[])
{
    // Check the arguments
    if ((args.length != 2))
	{
	System.out.println("\n\tUsage: java TelGen prefix postfix-length\n\n\t"+
			"For example: java TelGen 0044 3\n"+
			"\twill generate the numbers from 0044000 up to 0044999\n\n"+
			"\tPlease note that postfix-length cannot be highner than 18.");
	}
	if (args.length == 2)
	{
		generatePostfix(args[0], Integer.parseInt(args[1]));
	}
	else System.exit(0);      
}//end of main 

private static void generatePostfix(String pre, long post)
{
	//construct the highest number
	long nine = 9;
	String maxnumberString = "";
	for (long count=1;count<=post;count++)
	{	
		maxnumberString += String.valueOf(nine);
	}
	//convert highest number to string so get its characters' length
	long maxnumberStringAsLong = 0;
	maxnumberStringAsLong=Long.parseLong((String)maxnumberString);

		//now build the post number
		for (long x=0;x<=maxnumberStringAsLong;x++)
		{
			if (String.valueOf(x).length()==post)//check length of generated number
			{
				System.out.println(pre + x);	
			}
			else //we need padding as String.valueOf(x).length() < post
			{
				long currentnumber = (long)x;
			//	System.out.println(x);
				
				long howmanypads = post - String.valueOf(x).length();
			//	System.out.println("I need to add "+howmanypads + " zeros");
				
				//Build the leading zeros
				String padzero = "";
				for (long i=0;i<howmanypads;i++)
				{
					padzero+="0";
				}
				//Display the final number
				System.out.println(pre + padzero + x);
			}			
		}
}

}//end of public class TelGen