Løsningsforslag 7

Fra Hiofwiki

Gå til: navigasjon, søk

Oppgave 7.1 Oppgave 17.1 0: 1: 34 45 1 12 2: 3: 3 4: 5: 6: 17 7: 8: 9: 10: 87 65 32 Oppgave 17.2 0: 1: 2: 34 3: 22 4: 6: 3 8: 10: 12: 17 14: 16: 18: 20: 87 21: 24 Overflowarea: 22: 45 23: 28 24: 65 25: 26 26: 32 27: 28: 1 29: 30 30: 12 31: Oppgave 17.3 0: 34 1: 1 2: 87 3: 3 4: 17 5: 6: 7: 8: 9: 10: 11: 45 12: 12 13: 14: 65 15: 32 16: 34%17=0 45%17=11 3%17=3 87%17=2 65%17=2 32%17=15 1%17=1 12%17=12 17%17=0 Oppgave 17.4 0: 34 1: 1 2: 87 3: 3 4: 5: 6: 7: 8: 9: 10: 11: 45 12: 12 13: 14: 65 15: 32 16: 17 (17%17=0 0+1%17=1 0-1%17=-1 (-1=16)) 17.5 Oppgave 7.2 import java.util.HashSet;

public class hash1 { static hash1<String>[] hash;

public static int makeHash(){

hashChar = hash1<String> new hash1[26]; for (int i=0; i<hash1.length(); i++) hash1[i] = new hashChar; }

   public static void AddHash(String s){
       int pos = s.toUpperCase().charAt(0) - 65;

hashChar[pos].add(s);

   }
   public static void Output(){
       for(int i=0; i<hash1.length;i++){
           System.out.println(hashChar[i]);
       }
   }
  public static void main(String[] args) {   
       makeHash();
       AddHash("Petter");
       AddHash("Per");
       AddHash("ole");
       Output(); 
   }

}