Computer Science, asked by gkdhanoa25, 1 month ago

Write a Java program to check whether a Given String ends with the contents of
another String
.

Answers

Answered by anindyaadhikari13
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.

  1. import java.util.*;
  2. public class StringOp {
  3. public static void main(String[] args) {
  4. Scanner sc=new Scanner(System.in);
  5. String a, b;
  6. System.out.print("Enter first string: ");
  7. a=sc.nextLine();
  8. System.out.print("Enter second string: ");
  9. b=sc.nextLine();
  10. if(a.endsWith(b))
  11. System.out.println("First string ends with the content of second string.");
  12. else
  13. System.out.println("First string doesn't end with the content of second string.");
  14. sc.close();
  15. }
  16. }

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