Array and String Manipulation Problems
dev.to·4h·
Discuss: DEV
🔧DSPy
Preview
Report Post

case 1 : Reverse an array using another array



class Main {
public static void main(String[] args) {
int [] num = {10,11,12,13,14,15,16};
System.out.println("Original Array :");
for(int i=0;i<num.length;i++){
System.out.print(num[i]+"  ");
}
//Create a result array to hold the required values, having the same length as num.
int [] result = new int[num.length];

// reverse the array here
for(int i=num.length-1,j=0;i>=0;i--){
result[j++]=num[i];
}
System.out.println();
System.out.println("Reversed  Array :");
// print the resultant array
for(int i=0;i<result.length;i++){
System.out.print(result[i]+"  ");
}
}
}


case 2 : Reverse an array in-place without extra space

  • A palindrome number is a number which remains the same when it is reversed.


class Main {
public s...

Similar Posts

Loading similar posts...