Problem: Array String to Integer

kelev

Mitglied
Hallo Leute,

bin kelev und beschäftige mich seit ein paar Tagen mit Java.

folgendes Problem:
Hashfunktion schreiben: h(s) = f(z1) + f(z2).. mod m
für eine geschlossene Hashtabelle

f(A)=1 ; f(B)= 2 usw. Alles Großbuchstaben.

gegeben ein String[] arr = {"ZERO","JO", "HIER"};

simple Idee:

- hole array String
- caste ersten Char des Strings nach Integer und ziehe 64 ab
- Wert zu result addieren

Fehlermeldung:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method parseInt(String) in the type Integer is not applicable for the arguments (char)

at test.hashfkt(test.java:10)
at test.main(test.java:20)

Code:
Java:
public class test {


	public static int hashfkt(String[] input, int m) {

		int result = 0;
		for (int i = 0; i < input.length; i++) {
			for(int j = 0; j < input[i].length(); j++)
			{
				int output = Integer.parseInt(input[i].charAt(j));
				result += (output - 64);
			}
		}
		result = result % m;
		return result;
	}
	public static void main(String[] args) {
		String[] arr = {"ZERO","JO", "HIER"};
		int m = 17;
		int a = hashfkt(arr, m);
		System.out.println(a);
	}
}


Kann bitte jemand paar Tips geben? Danke im Voraus.
 

Zurück
Oben