Denis_Hristov

BroiNaChisla

Apr 13th, 2021 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class BroiNaChisla {
  5.     public static void SortArr(int [] arr){
  6.         int Buff;
  7.         for(int i = 0; i < arr.length - 1 ; i++){
  8.             for(int j = 0; j < arr.length - i - 1; j++){
  9.                 if(arr[j] > arr[j + 1]){
  10.                     Buff = arr[j];
  11.                     arr[j] = arr[j + 1];
  12.                     arr[j + 1] = Buff;
  13.                 }
  14.             }
  15.         }
  16.     }
  17.     public static void Counting(int [] arr, ArrayList<Integer>MyList){
  18.         int NumCount = 0;
  19.         int CurrentEllement = 0;
  20.         for (int i = 0; i < arr.length; i++) {
  21.             CurrentEllement = arr[i];
  22.             if(!MyList.contains(arr[i])){
  23.                 for (int j = 0; j < arr.length; j++) {
  24.                     if (CurrentEllement == arr[j]) {
  25.                         NumCount++;
  26.                     }
  27.                 }
  28.                 System.out.println(CurrentEllement + " - " + NumCount + " time/s");
  29.             }
  30.             MyList.add(CurrentEllement);
  31.             NumCount = 0;
  32.         }
  33.         System.out.println(MyList);
  34.     }
  35.     public static void main(String[] args) {
  36.         Scanner scan = new Scanner(System.in);
  37.  
  38.         ArrayList<Integer> MyList = new ArrayList<>();
  39.  
  40.         System.out.println("Input number of elements: ");
  41.         int n = scan.nextInt();
  42.         int[] arr = new int[n];
  43.  
  44.         for (int i = 0; i < arr.length; i++) {
  45.             System.out.printf("Input [%d] element: ", i);
  46.             arr[i] = scan.nextInt();
  47.         }
  48.  
  49.         SortArr(arr);
  50.         Counting(arr, MyList);
  51.     }
  52. }
Add Comment
Please, Sign In to add comment