Note: All basic exercises can not be based on the function of the tool function
First, reverse the sentence
Description: An English sentence is emitted in reverse order by word. For example "I am a boy", in reverse order after the "Boy a AM I" all the words are separated by a space, the statement in addition to the English letter, no longer contain other characters interface Description/** * Inverted sentence * * @param sentence original sentence * @return inverted sentence */public string Reverse (string sentence);
Second, synonyms maintain a given interface, set two words to each other synonyms. Synonyms have mutual transitive, if A and B are synonyms, B and C are synonyms, then A, B, C are synonyms. requires an interface to query a given two but whether it is a synonym relationship. and can provide the interface to clear all the synonyms relationship. Interface Description/** * Set 2 words for synonyms * @param word1 word one * @param word2 word two * @return 0 for success,-1 for failure or other exception */public int setsynonyms (String word1 , String word2)/** * Determines whether 2 words are synonyms (the same word is considered synonyms) * @param word1 Word one * @param word2 Word two * @return for synonyms return true, otherwise return false */public Boo Lean issynonyms (String word1, String word2)/** * Clear synonyms between words */public void clearrelations ()
Third, the number upside down
Description: Enter an integer, the integer in the form of a string output, the program does not consider the case of complex numbers, if the number contains 0, the reverse form also contains 0, if the input is 100, then the output is 001 interface Description/** * Reverse sentence * * @param sentence original sentence * @return The inverted sentence */public String reverse (int number);
Four, the Serpentine matrix
Description: The Serpentine matrix is a matrix triangle that is arranged in sequence by a natural number starting at 1. Input positive integer n (n not greater than 100) outputs a serpentine matrix of n rows. Sample input: 5 sample output: 1 3 6 5 9 164 8 227 12 18 21 2311 19 20 24 25 Interface Description/** * * Output into a number not greater than 100, resulting in a serpentine matrix string * * For example, input 5 o'clock, resulting in the following serpentine matrix output string, separated by a space between each number * 1 3 6 * 2 5 9 14 16 * 4< C15/>8 * 7 + * * * * * @param number not greater than 100 * @return Serpentine matrix string (need to control line wrapping) */pub LIC String getresult (int number);
OJ Beginner-sentence reverse order, synonyms maintenance, digital inversion, serpentine matrix