0% found this document useful (0 votes)
17 views4 pages

String

Uploaded by

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

String

Uploaded by

ANITHARANI K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Replace Case:

import [Link].*;

class HelloWorld {
public static void main(String[] args) {
String a = "HelLO";
String output = "";

for (int i = 0; i < [Link](); i++) {


char c = [Link](i);
if (c >= 'a' && c <= 'z') {
// Convert lowercase to uppercase by subtracting 32
output += (char) (c - 32);
} else if (c >= 'A' && c <= 'Z') {
// Convert uppercase to lowercase by adding 32
output += (char) (c + 32);
} else {
// If the character is not an alphabet, keep it unchanged
output += c;
}
}
[Link](output);
}
}

Remove vowel:

import [Link].*;

class HelloWorld {
public static void main(String[] args) {
String a = "HelLO";

for (int i = 0; i < [Link](); i++) {


char c = [Link](i);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
continue;
} else {
[Link](c);
}
}
}
}

Palindrome
import [Link].*;

class HelloWorld {
public static void main(String[] args) {
String X = "arorA";
String rev="";
String a=[Link]();
for(int i=[Link]()-1;i>=0;i--)
{
rev=rev+[Link](i);
}
if([Link](rev))
{
[Link]("Palindrome");
}
else
{
[Link]("Not a Palindrome");
}
}
}

Reverse String

import [Link].*;

class HelloWorld {
public static void main(String[] args) {
String a = "anitharani";
String rev="";

for(int i=[Link]()-1;i>=0;i--)
{
rev=rev+[Link](i);
}
[Link](rev);

}
}

Remove Alphabets

import [Link].*;

class HelloWorld {
public static void main(String[] args) {
String a = "AniTha";

for (int i = 0; i < [Link](); i++) {


char c = [Link](i);
if (c>='A'&&c<='Z')
{
continue;
} else {
[Link](c);
}
}
}
}

String frequency

public class CharacterFrequency {


public static void main(String[] args) {
String str = "Malayalam";

int[] frequency = new int[256];

for (int i = 0; i < [Link](); i++) {


char c = [Link](i);
frequency[c]++;
}

[Link]("Character frequencies:");
for (int i = 0; i < [Link]; i++) {
if (frequency[i] != 0) {
[Link]("'" + (char) i + "': " + frequency[i]);
}
}
}
}

Anagram:

import [Link];

public class AnagramCheck {


public static void main(String[] args) {
String str1 = "listen";
String str2 = "silent";
str1 = [Link]("\\s", "").toLowerCase();
str2 = [Link]("\\s", "").toLowerCase();

if ([Link]() != [Link]()) {
[Link]("The strings '" + str1 + "' and '" + str2 + "' are not
anagrams.");
return;
}

char[] charArray1 = [Link]();


char[] charArray2 = [Link]();
[Link](charArray1);
[Link](charArray2);

if ([Link](charArray1, charArray2)) {
[Link]("The strings '" + str1 + "' and '" + str2 + "' are anagrams.");
} else {
[Link]("The strings '" + str1 + "' and '" + str2 + "' are not
anagrams.");
}
}
}

String Replace

public class ReplaceWordInString {


public static void main(String[] args) {
String sentence = "Hello AR, Nice to meet you";
String oldWord = "AR";
String newWord = "Anitha";

// Replace the old word with the new word in the sentence
String modifiedSentence = [Link](oldWord, newWord);

// Print the modified sentence


[Link]("Original sentence: " + sentence);
[Link]("Modified sentence: " + modifiedSentence);
}
}

You might also like