0% found this document useful (0 votes)
12 views2 pages

Java Exp 3.1 Alasso

The document describes an experiment to create a Java application that finds the longest palindrome in a given string by appending the reversed string. It includes the student details, aim, objectives, and algorithm used to find the longest palindrome.

Uploaded by

Abhay Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Java Exp 3.1 Alasso

The document describes an experiment to create a Java application that finds the longest palindrome in a given string by appending the reversed string. It includes the student details, aim, objectives, and algorithm used to find the longest palindrome.

Uploaded by

Abhay Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 3.

Student Name: Shashi Ranjan Mehta UID: 21BCS7093


Branch: BE-CSE Section/Group:FL-601 B
Semester: 6 Date of Performance:06-03-2024
Subject Name: Java Lab
Subject Code:21CSH-319

1. Aim: Create a palindrome creator application for making a longest possible palindrome out of
given input string.
2. Objective:
• To learn about concept of HashMap in java.

• To learn about concept of String in java.

3. Algo. /Approach and output:

import java.util.Scanner;
public class palindroome {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();

String longestPalindrome = createLongestPalindrome(input);


System.out.println("Longest Palindrome: " + longestPalindrome);
}
public static String createLongestPalindrome(String input) {
if (input == null || input.length() == 0) {
return "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(input);
String reversedInput = new StringBuilder(input).reverse().toString();
stringBuilder.append(reversedInput);
return stringBuilder.toString();
}
}

Output:-

You might also like