fork download
  1. import java.util.Arrays;
  2.  
  3. public class Main {
  4. public static void main(String args[])
  5. {
  6. //Part 1
  7. Integer[] arr1 = {21,32,45,12,6,45,15,21,35,45,12,11,12,13,12};
  8. Integer[] arr2 = Arrays.copyOf(arr1, arr1.length);
  9. int[] arr3 = new int[arr1.length];
  10. int max=0;
  11. int min=0;
  12. int entry=0;
  13.  
  14. //Part 2
  15. System.out.println("The size of arr1 is: " + arr1.length);
  16.  
  17. //Part 3
  18. for(int i=0;i<arr1.length;i++)
  19. {
  20. if (arr1[i]>max)
  21. max = arr1[i];
  22. min = max;
  23. }
  24. System.out.println("The largest value in the array is: " + max);
  25.  
  26. //Part 4
  27. for(int i=0;i<arr1.length;i++)
  28. {
  29. if (arr1[i]<min)
  30. min = arr1[i];
  31. }
  32. System.out.println("The smallest value in the array is: " + min);
  33.  
  34. //Part 5
  35. java.util.Set<Integer> uniqueElems = new java.util.TreeSet<Integer>(Arrays.asList(arr1));
  36. for(Integer element: uniqueElems)
  37. {
  38. int count = 0;
  39. for(int i=0; i<arr1.length;i++)
  40. {
  41. if (element==arr1[i])
  42. {
  43. count++;
  44. }
  45. }
  46. System.out.println(element + " has " + count + " entries in the array.");
  47. }
  48.  
  49. //Part 6
  50. System.out.println("arr1 incremented by 5 equals:");
  51. for(int i=0;i<arr1.length;i++)
  52. {
  53. arr2[i]=arr1[i] + 5;
  54. }
  55. System.out.println(Arrays.toString(arr2));
  56. }
  57.  
  58. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
The size of arr1 is: 15
The largest value in the array is: 45
The smallest value in the array is: 6
6 has 1 entries in the array.
11 has 1 entries in the array.
12 has 4 entries in the array.
13 has 1 entries in the array.
15 has 1 entries in the array.
21 has 2 entries in the array.
32 has 1 entries in the array.
35 has 1 entries in the array.
45 has 3 entries in the array.
arr1 incremented by 5 equals:
[26, 37, 50, 17, 11, 50, 20, 26, 40, 50, 17, 16, 17, 18, 17]