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

Lab Assignment JAVA

The document contains Java code that defines methods for determining if a string is a palindrome and removing duplicate characters from a string. The isPalindrome method takes a string as input, reverses the characters, and compares it to the original to check for equality. The removeDuplicates method copies the input string to a character array, iterates through to only include the first instance of each character.

Uploaded by

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

Lab Assignment JAVA

The document contains Java code that defines methods for determining if a string is a palindrome and removing duplicate characters from a string. The isPalindrome method takes a string as input, reverses the characters, and compares it to the original to check for equality. The removeDuplicates method copies the input string to a character array, iterates through to only include the first instance of each character.

Uploaded by

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

import java.lang.

String;
import java.util.;
public class StringTest {

public static String str;

public static boolean isPalinDrome(String str)


{

int length = str.length();


if (length % 2 == 0)
{
char[] array = new char[50];
char[] array1 = new char[50];

for(int count = 0; count length; count++ )


{
str.getChars( 0, (length2-1), array, 0);

for(int count = 0; count length; count++ )


{
str.getChars( length, (length2-1), array1, 0);
}

if ( array == array1)
{
System.out.println(The Given string is PalinDrome);
return true;
}
else
{
return false;
}

}
else
{
char[] array = new char[50];
char[] array1 = new char[50];
for(int count = 0; count length2; count++ )
{
str.getChars( 0, (length2-1), array, 0);

}
for(int count = 0; count length2; count++ )
{
str.getChars( length-1, (length2), array1, 0);

}
if ( array == array1)
{
System.out.println(The Given string is PalinDrome);
return true;
}
else
{
return false;
}
}
}
public static void removeDuplicates(String values)
{

int len = values.length();


char[] str= new char[50];
for (int count = 0; count len; count++ )
{
str[count]= values.charAt(count);
}
if (str == null)
return;

int tail = 1;
for (int i = 1; i len; ++i) {
int j;
for (j = 0; j tail; ++j) {
if (str[i] == str[j])
break;
}
if (j == tail) {
str[tail] = str[i];
++tail;
}
}
str[tail] = 0;
}
}

You might also like