Write a Java program to check whether a Given String ends with the contents of
another String
.
Answers
Answered by
4
Required Answer:-
Question:
- Write a Java program to check whether a string ends with the content of another string.
Solution:
Here is the program.
- import java.util.*;
- public class StringOp {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- String a, b;
- System.out.print("Enter first string: ");
- a=sc.nextLine();
- System.out.print("Enter second string: ");
- b=sc.nextLine();
- if(a.endsWith(b))
- System.out.println("First string ends with the content of second string.");
- else
- System.out.println("First string doesn't end with the content of second string.");
- sc.close();
- }
- }
Explanation:
- The endsWith() function checks if a given string ends with another string or not. Using this function, we will check if the string ends with content of another string or not.
Output is attached.
Attachments:
Similar questions