Having trouble with Java exercise for University (Strings) -
so learning java @ university, , still @ beginner level bare me. have encountered problem describes following...
given 2 strings, print true if either of strings appears @ end of other string, ignoring upper/lower case differences (in other words, computation should not "case sensitive").
ok have established need allow input of 2 strings. assume need if/else statement, if checks both strings see whether or not characters of other string occur @ end of string using ignorecase. if either string has characters of other string @ end, print true
and else, print false.
i know how input 2 strings, , implement if else statement, problem is, how scan string see if contains contents of string? , how specify has found @ end of string. ie.
"hiabc", "abc" -> true "abc", "hiabc" -> true "abc", "abxabc" -> true "abc", "abxaxc" -> false
i have checked many online tutorials try , find syntax this, cannot seem find any.
any appreciated
not sure if you're allowed use these builtin methods, easiest thing call string.endswith(string)
. unfortunately, don't have case-insensitive variant, convert both strings lower case (or upper case, same-same). e.g.:
string str1lower = str1.tolowercase(); string str2lower = str2.tolowercase(); if (str1lower.endswith(str2lower) || str2lower.endswith(str2lower) { system.out.println ("one of strings end of other"); } else { system.out.println ("bummer."); }
Comments
Post a Comment