Please I need to complete the requirements in the code import java.util.Scanner; public class Palindrome { public static void main(String[] args) { String readUserSequence; int Lenght =20; boolean flag=true; Scanner sc=new Scanner(System.in); System.out.println("Please enter the Sequence of numbers:"); readUserSequence=sc.nextLine(); int len=readUserSequence.length(); for(int i=0;i
Please I need to complete the requirements in the code
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
String readUserSequence;
int Lenght =20;
boolean flag=true;
Scanner sc=new Scanner(System.in);
System.out.println("Please enter the Sequence of numbers:");
readUserSequence=sc.nextLine();
int len=readUserSequence.length();
for(int i=0;i<len/2;i++)
{
char f=readUserSequence.charAt(i);
char e=readUserSequence.charAt(len-i-1);
if(f!=e)
{
flag=false;
}
}
if(flag==true)
{
System.out.println("Your Sequence is palindrome");
}
else
{
System.out.println("Your Sequence is not palindrome");
}
}
}
Method displayArray(int[] arrayToDisplay)
This method accepts an array and displays it.
Write a test program that do the following:
- Create two arrays of size 30.
- Call readUserSequence(…) method to read data from the user and fill the arrays
- Call displayArray(…)to print the arrays.
- Pass the arrays to the isPalindrome(…) If the user’s sequence is palindrome then display "Your array is palindrome.", if not then display "Your array is not palindrome."
the sample output
Please enter the 5 elements of the first array:
2
4
0
4
2
Your array is: [2, 4, 0, 4, 2]
Your array is palindrome!
Please enter the 5 elements of the second array:
6
2
0
6
2
Your array is: [6, 2, 0, 6, 2]
Your array is not palindrome!
Step by step
Solved in 3 steps with 5 images