Advertisement
Guest User

Konrad Zadanie 1 :>

a guest
Feb 25th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. class Szukaj {
  2.  
  3.     public static void main(String[] Args) {
  4.         int[] wek = {14, 7, 9, 12, 13, 14, 17, 45, 14, 57, 89, 95, 14};
  5.         int liczba_szukana = 14;
  6.         StringBuilder wynik = new StringBuilder("Liczba " + liczba_szukana + " znajduje siΔ™ w indeksie (");
  7.         for (int j = 0; j < wek.length; j++) {
  8.             if (wek[j] == liczba_szukana) wynik.append(j).append(",");
  9.         }
  10.         if (wynik.charAt(wynik.length() - 1) == ',')
  11.             System.out.println(wynik.substring(0, wynik.length() - 1) + ")");
  12.         else if (wynik.charAt(wynik.length() - 1) == '(')
  13.             System.out.println("Szukanej liczby (" + liczba_szukana + ") nie ma w tablicy");
  14.         else
  15.             System.out.println(wynik.append(")"));
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement