Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Szukaj {
- public static void main(String[] Args) {
- int[] wek = {14, 7, 9, 12, 13, 14, 17, 45, 14, 57, 89, 95, 14};
- int liczba_szukana = 14;
- StringBuilder wynik = new StringBuilder("Liczba " + liczba_szukana + " znajduje siΔ w indeksie (");
- for (int j = 0; j < wek.length; j++) {
- if (wek[j] == liczba_szukana) wynik.append(j).append(",");
- }
- if (wynik.charAt(wynik.length() - 1) == ',')
- System.out.println(wynik.substring(0, wynik.length() - 1) + ")");
- else if (wynik.charAt(wynik.length() - 1) == '(')
- System.out.println("Szukanej liczby (" + liczba_szukana + ") nie ma w tablicy");
- else
- System.out.println(wynik.append(")"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement