Java functions and loops
Java functions and loops
toString()
Converts an object to a string representation.
length()
Returns the length of a string or array.
charAt(index)
Returns the character at a given index.
substring(start, end)
Extracts part of a string.
equals()
Compares two strings for equality.
String str1 = "Hello";
String str2 = "hello";
System.out.println(str1.equals(str2)); // Output: false
equalsIgnoreCase()
Compares two strings, ignoring case differences.
toUpperCase() / toLowerCase()
Converts a string to uppercase or lowercase.
replace(oldChar, newChar)
Replaces characters in a string.
trim()
Removes leading and trailing spaces.
split(delimiter)
Splits a string into an array based on a delimiter.
parseInt() / parseDouble()
Converts a string into an integer or double.
Math.pow(base, exponent)
Raises a number to a power.
Math.random()
Generates a random number between 0.0 and 1.0.
System.out.println(Math.random());
2. Real-Life Application Problems
if (isStrongPassword(password)) {
System.out.println("Your password is strong.");
} else {
System.out.println("Weak password! Follow the rules.");
}
}