classMain{publicstaticvoidmain(String[]args){int[]num={10,11,12,13,14,15,16};System.out.println("Original Array :");for(inti=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=newint[num.length];// reverse the array herefor(inti=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(inti=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.
case 3 : Check whether the given string is a palindrome or not
classMain{publicstaticvoidmain(String[]args){Stringstr="abcdcba";intleft=0;intright=str.length()-1;booleanflag=true;while(left<right){if(str.charAt(left)!=str.charAt(right)){flag=false;break;}left++;right--;}if(flag==true){System.out.println(str+" is palindrome number");}else{System.out.println(str+" is not palindrome number");}}}
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)