JAVA 11
Displacement matchCount() Homework 2 Guest on 19th September 2022 05:51:39 AM
  1. public class CharCountDist {
  2.     public static void main(String[] args) {
  3.         //System.out.println(displacement("ABBA", 2));
  4.         System.out.println(displacement("LCYFQPNGCYTNKVVEAKKYNKTFSWDYRNAEERQQOCCMHSPFSHAEKRZIUVLEIWPYYAZINWAEVYDFIZCYDF",5));
  5.     }
  6.  
  7.     //match counter for comparing two strings.
  8.     public static int matchCount(String text1, String text2) {
  9.         char[] strArr1;
  10.         char[] strArr2;
  11.         strArr1 = text1.toCharArray();
  12.         strArr2 = text2.toCharArray();
  13.         int count = 0;
  14.         for (int i = 0; (i < strArr1.length) && (i < strArr2.length); i++) {
  15.             if (strArr1[i] == strArr2[i]) {
  16.                 count++;
  17.             }
  18.         }
  19.         return count;
  20.     }
  21.  
  22.     //create displacement of a string using spaces
  23.     public static int displacement(String text, int disp) {
  24.         String text2 = text;
  25.         for (int i = 0; i < disp; i++) {
  26.             text2 = " " + text2;
  27.         }
  28.         return matchCount(text,text2);
  29.     }
  30. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.