ItsMeLucifer

Funkcja Hash Egzamin PPJP

Mar 5th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. public static void main(String[] args) {
  2.      String[][] tabliczka = new String[3][3];
  3.         tabliczka[0][0]="ELA";
  4.         tabliczka[1][0]="ABA";
  5.         tabliczka[2][0]="ABBA";
  6.        
  7.         hash(tabliczka);
  8.        
  9.     }
  10.     public static int[] hash (String[][] tab) throws NullPointerException{
  11.         int[] tablicka = new int[tab.length];
  12.         int wynikk=0;
  13.         for (int i=0;i<tab.length;i++){
  14.             String x = tab[i][0];
  15.            
  16.             int wynik=0;
  17.            
  18.             for(int j=0;j<x.length();j++){
  19.                 char c = x.charAt(j);
  20.                 int ascii = ((int)c)-64;
  21.                 wynik = ascii*(j+1);
  22.                 wynikk+=wynik;
  23.             }
  24.             int numer = 1;
  25.             do{
  26.             if(tab[i][numer]==null && numer<tab.length){
  27.             tab[i][numer] = Integer.toString(wynikk);
  28.             wynikk=0;
  29.             System.out.println(tab[i][1]);
  30.             numer++;
  31.             }else{
  32.                 numer++;
  33.             }
  34.             }while(tab[i][numer]!=null && numer<tab.length);
  35.         }
  36.        
  37.         return tablicka;
  38.     }
Add Comment
Please, Sign In to add comment