Pages

Tuesday, July 3, 2012

interChange program in java

Write a program to accept a String and interchange the first character with the last character.

class interChange
{
public static void main(String args[])
{
String val=args[0];
String f,l,newrep;
int len;
len=val.length();
f=val.substring(0,1);
l=val.substring(len-1,len);

System.out.println(val);
newrep=l+val.substring(1,len-1)+f;
System.out.println(newrep);
}
}

No comments:

Post a Comment