Advertisement
Niemampomyslu

Untitled

Oct 25th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class WyswietlanieWektora {
  2.  
  3. static void wyswietlWektor(int[] tablica){
  4. for(int liczba : tablica);
  5. System.out.print(liczba + " ");
  6. }
  7.  
  8. static void inwersja(int[] tablica) {
  9. int i = 0;
  10. int j = tablica.length - 1;
  11. int pomoc;
  12.  
  13. while (i < j) {
  14. pomoc = tablica[i];
  15. tablica[i] = tablica[j];
  16. tablica[j] = pomoc;
  17. i++;
  18. j--;
  19. }
  20. }
  21.  
  22. public static void main(String[] args) {
  23.  
  24. int[] wektor = {4, 2, 7, 3, 9, 1, 8, 5}; // utworzenie wektora
  25. wyswietlWektor(wektor);
  26. inwersja(wektor);
  27. wyswietlWektor(wektor);
  28.  
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement