Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class BroiNaChisla {
- public static void SortArr(int [] arr){
- int Buff;
- for(int i = 0; i < arr.length - 1 ; i++){
- for(int j = 0; j < arr.length - i - 1; j++){
- if(arr[j] > arr[j + 1]){
- Buff = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = Buff;
- }
- }
- }
- }
- public static void Counting(int [] arr, ArrayList<Integer>MyList){
- int NumCount = 0;
- int CurrentEllement = 0;
- for (int i = 0; i < arr.length; i++) {
- CurrentEllement = arr[i];
- if(!MyList.contains(arr[i])){
- for (int j = 0; j < arr.length; j++) {
- if (CurrentEllement == arr[j]) {
- NumCount++;
- }
- }
- System.out.println(CurrentEllement + " - " + NumCount + " time/s");
- }
- MyList.add(CurrentEllement);
- NumCount = 0;
- }
- System.out.println(MyList);
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- ArrayList<Integer> MyList = new ArrayList<>();
- System.out.println("Input number of elements: ");
- int n = scan.nextInt();
- int[] arr = new int[n];
- for (int i = 0; i < arr.length; i++) {
- System.out.printf("Input [%d] element: ", i);
- arr[i] = scan.nextInt();
- }
- SortArr(arr);
- Counting(arr, MyList);
- }
- }
Add Comment
Please, Sign In to add comment