Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. import java.util.Random;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. // write your code here
  9. Scanner in = new Scanner(System.in);
  10. par p = new par();
  11. System.out.println("Введите кол-во элементов: ");
  12. int n = in.nextInt();
  13. p.n=n;
  14. int x[] = new int[p.n];
  15. inp_random(x, p);
  16. out_array(x,p);
  17. System.out.println(p.n);
  18. delete(x,5,p);
  19. out_array(x,p);
  20. System.out.println(p.n);
  21. Arrays.sort(x);
  22. out_array(x,p);
  23. Arrays.fill(x,5);
  24. out_array(x,p);
  25. int[] y = new int[x.length];
  26. Arrays.equals(x,y);
  27.  
  28.  
  29. }
  30.  
  31. public static void inp_random(int[] a,par n){
  32. Random in=new Random();
  33. for(int i=0;i<n.n;i++){
  34. a[i]=in.nextInt(100);
  35. }
  36. }
  37.  
  38. public static void inp_array(int[] a, par n) {
  39. Scanner in = new Scanner(System.in);
  40. System.out.println("Введите " + n.n + " чисел");
  41. for (int i = 0; i < n.n; i++) {
  42. a[i] = in.nextInt();
  43. }
  44. }
  45.  
  46. public static void change(par p,int l){
  47. {p.n=l;}
  48. }
  49.  
  50. public static void delete(int a[],int z,par n){
  51. int j=search_array(a,z);
  52. int[]x=new int[a.length-1];
  53. for(int i=0;i<a.length-1;i++){
  54. if(i<j)x[i]=a[i];
  55. if(i>=j)x[i]=a[i+1];
  56. }
  57. change(n,x.length);
  58. System.arraycopy(x,0,a,0,n.n);
  59. }
  60.  
  61. public static void out_array(int[] a,par n) {
  62. System.out.println("Вывод массива: ");
  63. for (int i = 0; i < n.n; i++) {
  64. System.out.print(a[i] + " ");
  65. }
  66. System.out.println();
  67. }
  68.  
  69. public static int search_array(int[] x, int n) {
  70. int i = 0;
  71. while (i < x.length) {
  72. if (x[i] == n){
  73. return i;
  74. }
  75. i++;
  76. }
  77. return -1;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement