Sunday, 17 July 2011

Program for reversing a array Without using another array

Class ReverseArray{
public static void main(String args[]){
char inputArray[]=args[0].toCharArray();
reverseArray(inputArray);
String outputString=String.copyValueOf(inputArray);
System.out.println(outputString);
}





private static void reverseArray(char[] inputArray){
for(int i=0;i<(inputArray.length)/2;i++){
char temp=inputArray[i];
inputArray[i]=inputArray[inputArray.length-1-i];
inputArray[inputArray.length-1-i]=temp;
}
}
}
Here user run :java ReverseArray shakti
output will be : itkahs

2 comments:

  1. Its really Help ful for me

    ReplyDelete
  2. This question really helps in the interview.thanks for posting this programe

    ReplyDelete