讲解:Java Computer Science Spring 2018Java

IntroductionRequirementCSE114: Computer Science 1 Spring 2018Homework2:Due Date: Homework2 is due by 11:59 PM on Monday, March 12, 2018. Submit your work(the .java source code files ONLY, not the compiled .class files!) through the “Homework2” linkon Blackboard. You may submit an unlimited number of times; we will only grade the last/latestsubmission attempt, but be sure to attach all of your files to each submission attempt. Be sure toinclude your name and Stony Brook ID number in a comment at the beginning of each file thatyou submit.Instructions: This assignment is worth 40 points (10 points per program).1. Write a method that checks whether the input string or a sentence (a string with spaces) is apalindrome or not. The method should be case insensitive and should ignore spaces. Write atest program that prompts the user to input a string and invokes this method. Some exampleruns are:Enter the input string: madamInput string madam is a palindromeEnter the input string: bananaInput string banana is NOT a palindromeEnter the input string: Race CarInput string Race Car is a palindromeEnter the input string: Too HOT to hootInput string Too HOT to hoot is a palindrome2. Two strings are anagrams if they are written using the same exact letters. Write a method tocheck if given two strings are anagrams or not. You have to ignore the case and spacecharacters. Write a test program for that prompts the user to input two strings and invokes thismethod. Some example runs are:Enter the first string: abbacbaEnter the second string: abcabbaabbacba and abcabba are anagramsEnter the first string: bananaEnter the second string: cabanabanana and cabana are NOT anagramsEnter the first string: Eleven plus twoEnter the second string: Twelve plus oneCSE114: Computer Science 1 Spring 2018Eleven plus two and Twelve plus one are anagrams3. Write down a sort method to sort an array of String using bubble-sort algJava代写回文实验 Computer Science Spring 2018代写Java实验orithm. Bubble sortalgorithm makes several passes through the array. On each pass, successive neighboring pairsare compared. If a pair is not in order, its values are swapped; otherwise the value remainsunchanged. The technique is called bubble sort or sinking sort because the smaller valuesgradually “bubble” their way to the top, and the larger values “sink” to the bottom.Write a test program that reads in 10 String values and invokes the bubble sort method. Displaythe sorted string array.Example run:Enter 10 strings: New York City, Austin, Dallas, Seattle, Washington D.C., Houston, Chicago,Las Vegas, Charlotte, Denver,Sorted strings: Austin, Charlotte, Chicago, Dallas, Denver, Houston, Las Vegas, New YorkCity, Seattle, Washington D.C.,4. Write a method to multiply two matrices. The header of the method is:?????? ?????? ??????[][] ??????????????(?????? [][] ?,??????[][] ?).To multiply matrix ? by matrix ?, the number of columns in ? must be the same as the numberof rows in ?, and the two matrices must have elements of thsame or compatible types. Let ?be the result of the multiplication. Assume the column size of matrix ? is ?. Each element? ?? = ? ?1 × ? 1? + ? ?2 × ? 2? + ⋯+ ? ?? × ? ?? .For example, the two 3 × 3 matrices ? and ?, ? is:(? 11? 12 ? 13? 21? 31? 22? 32? 23? 33) × (? 11 ? 12 ? 13? 21? 31? 22? 32? 23? 33) = (? 11? 12 ? 13? 21? 31? 22? 32? 23? 33)Where ? ?? = ? ?1 × ? 1? + ? ?2 × ? 2? + ? ?3 × ? 3? .Write a test program that prompts the user to enter two 3 × 3 matrices and displays theirproduct. Here is a sample run:Enter matrix1: 1 2 3 4 5 6 7 8 9Enter matrix2: 0 2 4 1 4.5 2.2 1.1 4.3 5.2Multiplication of the matrices is: 5.3 23.9 2411.6 56.3 58.217.9 88.7 92.4& 转自:http://ass.3daixie.com/2018052610002621.html

你可能感兴趣的:(讲解:Java Computer Science Spring 2018Java)