1)
Code:
class LoginManager {
public void login(String email, String password) {
if (email.equals("[email protected]") && password.equals("sarathi123///")) {
System.out.println("Login successful with email.");
} else {
System.out.println("Login failed with email.");
}
}
public void login(long mobileNumber, String password) {
if (mobileNumber == 1234567890L && password.equals("pass123")) {
System.out.println("Login successful with mobile number.");
} else {
System.out.println("Login failed with mobile number.");
}
}
public static void main(String[] args) {
LoginManager manager = new LoginManager();
manager.login("[email protected]", "sarathi123///");
manager.login("[email protected]", "wrong");
manager.login(1234567890L, "pass123");
manager.login(1111111111L, "wrong");
}
}
Output:
2)
Code:
public class Arrange {
public String[] sort(String[] s) {
for (int i = 0; i < s.length; i++) {
for (int j = i + 1; j < s.length; j++) {
if (s[i].compareTo(s[j]) > 0) {
String temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
return s;
}
public int[] sort(int[] a) {
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
return a;
}
public static void main(String[] args) {
Arrange obj = new Arrange();
String[] strArr = {"Banana", "Apple", "Mango"};
int[] intArr = {45, 12, 78, 5};
strArr = obj.sort(strArr);
intArr = obj.sort(intArr);
System.out.println("Sorted Strings:");
for (int i = 0; i < strArr.length; i++) {
System.out.println(strArr[i]);
}
System.out.println("Sorted Integers:");
for (int i = 0; i < intArr.length; i++) {
System.out.println(intArr[i]);
}
}
}
Output: