Question

Java ; Given two Strings, return true if the shorter of the two Strings appears at...

Java ; Given two Strings, return true if the shorter of the two Strings appears at the very end of the other string, ignoring upper/lower case differences and false otherwise

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

import java.util.Scanner;

public class Sample {
    public static void main(String args[]) {
        String s1, s2;

        Scanner in = new Scanner(System.in);
        System.out.println("Enter string 1:");
        s1 = in.nextLine();
        System.out.println("Enter string 2:");
        s2 = in.nextLine();
        if (Strings(s1, s2)) {
            System.out.println("The longer string ends with shorter string");
        } else
            System.out.println("The longer string does not end with shorter string");
    }

    public static boolean Strings(String s1, String s2) {
        if (s1.length() >= s2.length()) {
            s1=s1.toLowerCase();
            s2=s2.toLowerCase();
            if (s1.endsWith(s2))
                return true;
            else
                return false;
        } else {
            s1=s1.toLowerCase();
            s2=s2.toLowerCase();
            System.out.println(s1);
            System.out.println(s2);
            if (s2.endsWith(s1))
                return true;
            else
                return false;
        }
    }
}

Output:

Add a comment
Know the answer?
Add Answer to:
Java ; Given two Strings, return true if the shorter of the two Strings appears at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given an array of strings, return true if each string's size is equal or greater than...

    Given an array of strings, return true if each string's size is equal or greater than the one before, otherwise return false. The array will be length 2 or more. Example 1: If the names array contains… “Edwin” “Satish” “Solomon” “Massoud” …then the function call stringsIncreasing (names, 4) returns true. Example 2: If the names array contains… “Janet” “Linda” “Jackie” “Marta” …then the function call stringsIncreasing (names, 4) returns false since string Jackie comes before Marta and has more letters...

  • Write a method will accept an array of Strings. This method should return the string that...

    Write a method will accept an array of Strings. This method should return the string that comes after all the other strings in lexicographical order. (Assume all the Strings only contain lower case letters. In Example: No number, no Capitals and no Symbols) lastString({“hola”, “word”, “night”, “boom”}) → “word” lastString({“java”, “is”, “so”, “much”, “fun”}) → “so” lastString({“i”, “love”, “java”}) → “love” //precondition: words.length >0 public static String lastString(String[] words) { }

  • Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if...

    Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if s1 is the reverse of s2, false otherwise. Then, draw the sequence of recursive calls for the following cases. Submit your diagrams in a PDF file called isReverseTrace.pdf. isReverse("happy", "yppah") will return true isReverse("cool", "loac") will return false isReverse("", "") will return true

  • /** Given an int array, return true if the array contains duplicate values. duplicateInts({3}) -> false...

    /** Given an int array, return true if the array contains duplicate values. duplicateInts({3}) -> false duplicateInts({1, 2}) -> false duplicateInts({7, 7}) -> true duplicateInts({1, 2, 3, 4, 5}) -> false duplicateInts({1, 2, 3, 2, 4, 5}) -> true **/ public static boolean duplicateInts(int[] numbers) { //your code here return false; }//end duplicateInts /** Given a String array, return true if the array contains duplicate values. Note: Capital letters count duplicateStrings({"a"}) -> false duplicateStrings({"a", "b", "c", "d"}) -> false duplicateStrings({"a",...

  • Styles 6 2. Modify the "LinkedStackOfStrings java" program given in the textbook (program 4.3.2) by adding...

    Styles 6 2. Modify the "LinkedStackOfStrings java" program given in the textbook (program 4.3.2) by adding a method "find0 that takes a string as an argument. It should return true if the string argument is in the linked stack and false otherwise. [Mo6.1] The main method should also be modified so that all the strings (other than the search string) inputted by the user are stored on the stack before calling the find0 method. Sample runs would be as follows....

  • C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask,...

    C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask, and get a character from the user. The function will return true if the character the user enters is NOT in either of the words, otherwise it will return false. Keep in mind that uppercase and lowercase letters are not the same. You will need to change both words and the character input by the user to the same case (upper or lower) -...

  • /**    Given a String and an array of two Strings,    return a three String...

    /**    Given a String and an array of two Strings,    return a three String array containing the strings in alphabetical order.    Note: Capital letters count    sort3Strings("wallace", {"washington", "irving"}) -> {"irving", "wallace", "washington"}    sort3Strings("wallace", {"washington", "Irving"}) -> {"Irving", "wallace", "washington"}    sort3Strings("Washington", {"irving", wallace"}) -> {"Washington", "irving", "wallace"}    sort3Strings("washington", {"washington", "Washington"}) -> {"Washington", "washington", "washington"} **/ public static String[] sort3Strings(String stringValue, String[] stringArray) {    //your code here    return new String[1]; }//end sort3Strings   ...

  • 39) Which function accepts two strings as arguments, returns "True" if the first string contains the...

    39) Which function accepts two strings as arguments, returns "True" if the first string contains the second string, and otherwise returns "False"? None of the above Contains Append Substring Concatenate

  • Java Programming Exercise Return true if the given string begins with "mix", except the 'm' can...

    Java Programming Exercise Return true if the given string begins with "mix", except the 'm' can be anything, so "pix", "9ix" .. all count. for example: mixStart("mix snacks") → true mixStart("pix snacks") → true mixStart("piz snacks") → false */ public boolean mixStart(String str) { *Need Help With Code Here* }

  • In JAVA, Given an array of strings, return a new array containing the first N strings....

    In JAVA, Given an array of strings, return a new array containing the first N strings. N will be in the range 1..length. wordsFront(["a", "b", "c", "d"], 1) → ["a"] wordsFront(["a", "b", "c", "d"], 2) → ["a", "b"] wordsFront(["a", "b", "c", "d"], 3) → ["a", "b", "c"]

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT