letters-and-numbers

Java repeated letter check in string

大兔子大兔子 提交于 2020-01-30 12:16:45
问题 I'm having problem figuring out how to check from users input letters that were repeated. Program needs to output repeated letter as true and if there isn't any then as false. Program should not count numbers or symbols as repeated. For example: User input: Chocolate Program Output: True User input: 112 cream Program Output: False 回答1: Here is another version, based on answer from @rell but with no HashSet or char[] creation. private static boolean check(String input) { for (int i = 0; i <

Separate Numbers and Letters

瘦欲@ 提交于 2019-12-11 11:25:55
问题 Let's say I have a String that says "Hello123" , how can I separate them to become s[0] = "Hello", s[1] = "123" ? I wish to use s.split() but I don't know what to put in the argument/parameter. 回答1: You could use a regular expression: String[] splitArray = subjectString.split( "(?x) # verbose regex mode on \n" + "(?<= # Assert that the previous character is... \n" + " \\p{L} # a letter \n" + ") # and \n" + "(?= # that the next character is... \n" + " \\p{N} # a digit. \n" + ") # \n" + "| # Or

subtracting letters in c

南笙酒味 提交于 2019-12-11 11:07:54
问题 I would like to know how to "subtract letters" in C: I mean, I have 2 letters, 'a' and 'c' and i want to execute 'c'-'a'='b' which is 3-1=2. How is it possible to obtain the same behaviour in C? I can conversion Letters->Numbers but how to manage the limited lenght of the alphabet? Thank you. 回答1: you can treat the letters as numbers and then add the letter 'a' back to normalize it so char c1 = 'a'; char c2 = 'c'; int diff = c2 - c1; //'c' - 'a' = 2 char ans = diff + 'a' - 1; //add 'a' and