mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 04:54:21 +08:00
style: enable StaticVariableName
in checkstyle (#5173)
* style: enable StaticVariableName in checkstyle * Refractored: enable StaticVariableName in checkstyle * style: mark more variables as `final` --------- Co-authored-by: vaibhav <vaibhav.waghmare@techprescient.com> Co-authored-by: vil02 <vil02@o2.pl>
This commit is contained in:
@ -11,15 +11,15 @@ public final class RabinKarp {
|
||||
private RabinKarp() {
|
||||
}
|
||||
|
||||
public static Scanner SCANNER = null;
|
||||
public static Scanner scanner = null;
|
||||
public static final int ALPHABET_SIZE = 256;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SCANNER = new Scanner(System.in);
|
||||
scanner = new Scanner(System.in);
|
||||
System.out.println("Enter String");
|
||||
String text = SCANNER.nextLine();
|
||||
String text = scanner.nextLine();
|
||||
System.out.println("Enter pattern");
|
||||
String pattern = SCANNER.nextLine();
|
||||
String pattern = scanner.nextLine();
|
||||
|
||||
int q = 101;
|
||||
searchPat(text, pattern, q);
|
||||
|
@ -5,13 +5,13 @@ package com.thealgorithms.others;
|
||||
*/
|
||||
import java.util.Scanner;
|
||||
|
||||
// An implementaion of string matching using finite automata
|
||||
// An implementation of string matching using finite automata
|
||||
public final class StringMatchFiniteAutomata {
|
||||
private StringMatchFiniteAutomata() {
|
||||
}
|
||||
|
||||
public static final int CHARS = 256;
|
||||
public static int[][] FA;
|
||||
public static int[][] fa;
|
||||
public static Scanner scanner = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -30,13 +30,13 @@ public final class StringMatchFiniteAutomata {
|
||||
int m = pat.length();
|
||||
int n = text.length();
|
||||
|
||||
FA = new int[m + 1][CHARS];
|
||||
fa = new int[m + 1][CHARS];
|
||||
|
||||
computeFA(pat, m, FA);
|
||||
computeFA(pat, m, fa);
|
||||
|
||||
int state = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
state = FA[state][text.charAt(i)];
|
||||
state = fa[state][text.charAt(i)];
|
||||
|
||||
if (state == m) {
|
||||
System.out.println("Pattern found at index " + (i - m + 1));
|
||||
@ -44,11 +44,11 @@ public final class StringMatchFiniteAutomata {
|
||||
}
|
||||
}
|
||||
|
||||
// Computes finite automata for the partern
|
||||
public static void computeFA(String pat, int m, int[][] FA) {
|
||||
// Computes finite automata for the pattern
|
||||
public static void computeFA(String pat, int m, int[][] fa) {
|
||||
for (int state = 0; state <= m; ++state) {
|
||||
for (int x = 0; x < CHARS; ++x) {
|
||||
FA[state][x] = getNextState(pat, m, state, x);
|
||||
fa[state][x] = getNextState(pat, m, state, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user