Write a program that accept two strings or two numbers from command line and create overloaded method that add these two numbers or concate two strings.

class P18
{
	static void add(int x,int y)
	{
		System.out.println(x+y);
	}
	static void add(String x,String y)
	{
		System.out.println(x+y);
	}
	public static void main(String args[])
	{
		String v1=args[0];
		String v2=args[1];
		try
		{
			int n1,n2;
			n1=Integer.parseInt(v1);
			n2=Integer.parseInt(v2);
			add(n1,n2);
		}
		catch(NumberFormatException e)
		{
			add(v1,v2);
		} 	
	}
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *