Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

Can someone help me with this java problem?

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

I have my program MyString. public class MyString { public static String reverse(String s) { String reverse = ""; for(int i=s.length() - 1; i >=0; i--) { reverse = reverse + s.charAt(i); } return reverse; } public static boolean isPalindrome(String s) { String a = reverse(s); if(a.equals(s)) { return true; } return false; } public static boolean match(String s1, String s2) { return s1.equals(s2); } public static int mismatchCount(String s1, String s2) { int counter = 0; for(int i=0; i < s1.length(); i++) { if(s1.charAt(i)!=s2.charAt(i)) { counter++; } } return counter; } public static boolean similar(String s1, String s2) { int mismatch = mismatchCount(s1,s2); return mismatch<=1; } public static void printPositions(String key, String target) { for(int j = 0; j <= target.length() - key.length(); j++) { if(target.substring(j,j+key.length()).equals(key)) { System.out.println(j); } } } }
Does this JUnit Test look okay? import junit.framework.TestCase; public class TestMyString extends TestCase { public void testReverse() { assertEquals(MyString.reverse("cat"),"tac"); } public void testisPalindrome() { assertEquals("isPalindrome","eye","eye"); //returns true if eye is the same when reversed assertEquals("isPalindrome","horse","horse"); //returns false when they aren't the same } public void testMatch() { assertEquals("match","dog","dog"); } public void testMismatchCount() { assertEquals("mismatchcount","bow","bow"); } public void testSimilar() { assertEquals("similar","boo","boo"); } }

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

seems to run and work ok - just add the usual public static void main(String[] args){ } - you can run all your tests within it.
i just have to test those five methods in the "Test Output" window, so i don't need to run it!
I've never used JUnit.....
Not sure what exactly it does, maybe I have, I know it's included in my IDE Netbeans....
I came up with the same answer as Snark
snarks right

Not the answer you are looking for?

Search for more explanations.

Ask your own question