Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1.  
  2. //Erstellen sie eine Klasse Kontaktliste, die die Variablen String in einem Feld mit Größe 100 hat
  3. //Alle Variablen sollen static sein
  4. //Schreiben sie eine Funktion eintrag(String kontakt), die, einen freien Platz sucht und den Kontakt einträgt,
  5. //falls dieser noch nicht vorhanden ist
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. public class Kontaktliste {
  19. public static String [] feld = new String [100];
  20. public static int anzahl = 0;
  21.  
  22. public static void eintrag(String kontakt)
  23. {
  24. String str ="";
  25. for(int i = 0; i < feld.length;i++)
  26. {
  27.  
  28. if(feld[i]==null)
  29. {
  30. feld[i]=kontakt;
  31. anzahl++;
  32. }
  33. str = feld[i];
  34. if(str.equals(kontakt))
  35. {
  36. break;
  37. }
  38. }
  39. }
  40.  
  41. public static String suchen(String a)
  42. {
  43.  
  44. for(int i = 0; i < feld.length;i++)
  45. {
  46.  
  47. String str = feld[i];
  48. if(str==null)
  49. {
  50. return "unbekannt";
  51. }
  52. if(str.contains(a)==true)
  53. {
  54. return feld[i];
  55. }
  56.  
  57.  
  58.  
  59. }
  60.  
  61. return "unbekannt";
  62. }
  63.  
  64.  
  65. public static void main (String [] args)
  66. {
  67.  
  68. eintrag("mueller 28008");
  69. eintrag("meyer 28007");
  70. System.out.println(suchen("28008"));
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement