Java Lab Manual
Java Lab Manual
import java.util.Scanner;
public class StringEqualityChecker
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
// Input first string
System.out.print("Enter the first string: ");
String firstString = scanner.nextLine();
// Input second string
System.out.print("Enter the second string: ");
String secondString = scanner.nextLine();
// Check if the strings are equal
if (areStringsEqual(firstString, secondString))
{
System.out.println("The strings are equal.");
}
else
{
System.out.println("The strings are not equal.");
}
// Close the scanner to avoid resource leak
scanner.close();
}
// Method to check whether two strings are equal
private static boolean areStringsEqual(String str1, String str2)
{
// Use equals method for string comparison
return str1.equals(str2);
}}
import java.util.Scanner;
// Input string
scanner.close();
int start = 0;
int end = charArray.length - 1;
charArray[start] = charArray[end];
charArray[end] = temp;
start++;
end--;