Advertisement
invina_

Untitled

Oct 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. int [] array50 = new int [50]; //создаем массив из 50 элементов в пределах от [1:100]
  7. String mass = new String();
  8. String mass2 = new String();
  9. int temp;
  10. for (int i =0; i< array50.length; i++)
  11. {
  12. array50[i] = (int)(Math.random()*100)+1;
  13. mass += array50[i] + " " ;
  14.  
  15. }
  16. System.out.println("Исходный массив : " + mass);// выводим исходный массив в строку
  17.  
  18. for (int i =0; i< array50.length; i+=2)//меняем четные и нечетные элементы массива местами
  19. { temp = array50[i];
  20. array50[i] = array50[i +1];
  21. array50[i +1] = temp;
  22. mass2 += array50[i]+" " +array50[i +1] +" ";
  23. }
  24. System.out.println("Измененный массив : " + mass2 );// выводим измененный массив в строку
  25.  
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement