0% found this document useful (0 votes)
7 views3 pages

Java String Operations Program Guide

The document outlines a Java program that implements various string operations, including finding string length, converting cases, comparing, concatenating, and reversing strings. It provides a step-by-step procedure for creating a Java project and class, along with an algorithm detailing the necessary functions. The program successfully demonstrates these string operations with example outputs.

Uploaded by

Almas Begam.A
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)
7 views3 pages

Java String Operations Program Guide

The document outlines a Java program that implements various string operations, including finding string length, converting cases, comparing, concatenating, and reversing strings. It provides a step-by-step procedure for creating a Java project and class, along with an algorithm detailing the necessary functions. The program successfully demonstrates these string operations with example outputs.

Uploaded by

Almas Begam.A
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

EX NO ROLL NO DATE

NAME OF THE EXPERIMENT


1B 24DI46 24-11-25

Write a Program to Implement Various Methods Supported by String Class in Java

AIM
To write a Java program that demonstrates various string operations such as finding string
length, converting to uppercase and lowercase, comparing strings, concatenating strings, and
reversing a string,

PROCEDURE
Step1. Open Netbeans Ide.
Step2. Create A New Java Project:
Step3 Click File → New Project → Java Application.
Step4 Enter Project Name And Click Finish.
Step3. Create A Java Class File.

ALGORITHM
Step1. Import the required package using:
import [Link].*;
Step2. Create a class named Operators.
step3. Declare integer variables a, b, c as class variables.
step4. Define the function void add() to:
• Assign values to a and b
• Add a and b and store the result in c
• Print the result
step5. Define the function void sub() to:
• Assign values to a and b
• Subtract b from a and store the result in c
• Print the result
step6. Define the function void mul() to:
• Assign values to a and b
• Multiply a and b and store the result in c
• Print the result
step7. Define the function void reg() to:
• Compare a and b using relational operators
• Print the comparison result
step8. Define the function void lag() to:
• Perform logical operations using logical operators
• Print the logical results
step9. Create the main() method.
step10. Create an object for the class.
step11. Call the functions add(), sub(), mul(), reg(), and lag() using the object.

PROGRAM
package stringmethods;
public class StringFunctions {
public static void main(String[] args) {
String str1 = "Hello";
String str2 = "World";
// strlen → length()
[Link]("Length of str1: " + [Link]());
// strupr → toUpperCase()
[Link]("Uppercase str1: " + [Link]());
// strlow → toLowerCase()
[Link]("Lowercase str2: " + [Link]());
// strcmp → compareTo()
String a = "apple";
String b = "banana";
[Link]("strcmp(a, b): " + [Link](b));
// strcat → concat() or +
String str3 = "Hello ";
str3 = [Link]("World"); // or str3 += "World";
[Link]("Concatenated string: " + str3);
// strrev → reverse using StringBuilder
String rev = "computer";
String reversed = new StringBuilder(rev).reverse().toString();
[Link]("Reversed string: " + reversed);
}
}
OUTPUT

RESULT
The program successfully performs different string operations in Java.

You might also like