Consider the following class definitions virtually identical
Solution
5) Answer
import java.util.Scanner;
class palindrome
{
//Recursive method to check palindrome
public static boolean isPalin(String str)
{
// If length is 0 or 1 then String is palindrome
if(str.length() == 0 || str.length() == 1)
return true;
if(str.charAt(0) == str.charAt(str.length()-1))
// Check for first and last char of String. If they are same then do the same thing for a substring with first and last char removed.
// Continue this until our string completes or condition fails.
return isPalin(str.substring(1, str.length()-1));
return false;
}
public static void main(String[]args)
{
//Scanner class object is created
Scanner scanner = new Scanner(System.in);
System.out.println(\"Enter the String for check:\");
//Accept a string
String string = scanner.nextLine();
// If function returns true then the string is palindrome else not palindrome
if(isPalin(string))
System.out.println(string + \" Palindrome\");
else
System.out.println(string + \" Not Palindrome\");
}
}
Output 1:
Enter the String for check:
thisis
thisis Not Palindrome
Output 2:
Enter the String for check:
madam
madam Palindrome
4) Answer:
public int average()
{
int sum = 0;
int cou = 0;
IntNode current = head;
//Checks for empty
if (head == null)
return 0;
//Loops till end of the linked list
while(current.getNext() != null)
{
//Calculates total
sum = sum + current.getDatum();
//Counter for number of items
cou++;
}
System.out.println(\"Average of the elements in the list = \" + (sum / cou));
}

