Equals & == in String
Data Type | Variable Name |
String | name |
String |
Prototype for the Parameterized Constructor, public Customer(String name, String email)
Use 'equals()' and 'equalsIgnoreCase()' to compare the email ids[Refer sample input & output ].
Consider the main class "Main.java".
The link to download the template code is given below
Code Template
Sample Input / Output 1:
Enter First Customer Details :
Sample Input / Output 2:
Problem Requirements:
Java
Keyword | Min Count | Max Count |
equals | 1 | - |
Keyword | Min Count | Max Count |
equalsIgnoreCase | 1 | - |
public class Customer {
private String name,email;
public Customer(String name, String email) {
this.name=name;
this.email=email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter First Customer Details :");
System.out.println("Enter Customer Name :");
String cus1 = sc.nextLine();
System.out.println("Enter Customer Email :");
String email1 = sc.nextLine();
System.out.println("Enter Second Customer Details :");
System.out.println("Enter Customer Name :");
String cus2 = sc.nextLine();
System.out.println("Enter Customer Email :");
String email2 = sc.nextLine();
Customer jp = new Customer(email1, email2);
if(email1.equals(email2)) {
System.out.println("The Email ids of "+cus1+" and "+cus2+" are equal");
}
else {
System.out.println("The Email ids of "+cus1+" and "+cus2+" are not equal");
}
System.out.println("Comparing without considering the cases :");
if(email1.equalsIgnoreCase(email2)) {
System.out.println("The Email ids of "+cus1+" and "+cus2+" are Equal");
}
else {
System.out.println("The Email ids of "+cus1+" and "+cus2+" are not equal");
}
}
}
Date
Rex figured out that the binary forms of the date, month, and year were 2 bits, 2 bits, and 2 bits rotated left in his LED board. Write a program to change the incorrect date, month, and year. use the Integer Wrapper Class rotateRight() method to print the correct date in International format.
The date format to be displayed in the output is (yyyy-mm-dd).
Input Format:
The first line is an integer that corresponds to the incorrect day number.
The second line is an integer that corresponds to the incorrect month number.
The third line is an integer that corresponds to the incorrect year.
Output Format:
The Output should display the correct date in a single line separated by slashes in the international format.
Sample Input:
20
36
7944
Sample Output:
1986/9/5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
a = Integer.rotateRight(a, 2);
b = Integer.rotateRight(b, 2);
c = Integer.rotateRight(c, 2);
System.out.println(c+"/"+b+"/"+a);
}
}
MOTIVATION :
“The way we spend our time defines who we are ”
Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.
VISITE MORE BLOGS