Advertisement
UniQuet0p1

Untitled

Feb 18th, 2022
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. package junit;
  2.  
  3. public class Code {
  4.     public static void main(String[] args) {
  5.        
  6.     }
  7.  
  8.     public static boolean isSpecial(int candidate) {
  9.         return candidate % 11 < 4;
  10.     }
  11.  
  12.     public static int longestStreak(String inputString) {
  13.  
  14.         if (inputString == null || inputString.equals("")){
  15.             return 0;
  16.         }
  17.  
  18.         int longest = 0;
  19.         String lastChar = null;
  20.         int currentStreakLenght = 0;
  21.         for (String currentChar : inputString.split("")) { //abbcccaaaad -  делим строку на символы
  22.             if (currentChar.equals(lastChar)) {
  23.                 currentStreakLenght++;
  24.             } else {
  25.                     currentStreakLenght = 1;
  26.                 }
  27.             System.out.println("alksdjlkas");
  28.             if (currentStreakLenght > longest){ //проверка на самое большое число
  29.                 longest = currentStreakLenght;
  30.             }
  31.  
  32.                 lastChar = currentChar;
  33.             }
  34.  
  35.             return longest;
  36.         }
  37.  
  38.  
  39.     public static Character mode(String inputString) {
  40.         if(inputString ==  null){
  41.             return null;
  42.         }
  43.         int modeCount = 0;
  44.         Character mode = null;
  45.         for (char c1 : inputString.toCharArray()){
  46.             int count = 0;
  47.             for (char c2 : inputString.toCharArray()){
  48.                 if (c1 == c2){
  49.                     count++;
  50.                 }
  51.             }
  52.             if (count > modeCount){
  53.                 modeCount = count;
  54.                 mode = c1;
  55.             }
  56.         }
  57.         return mode;
  58.     }
  59.  
  60.     public static int getCharacterCount(String allCharacters, char targetCharacter) {
  61.         int count = 0;
  62.  
  63.         for (Character letter: allCharacters.toCharArray()) {
  64.  
  65.             if (letter.equals(targetCharacter)) {
  66.  
  67.                 count++;
  68.             }
  69.         }
  70.  
  71.         return count;
  72.     }
  73.  
  74.     public static int[] removeDuplicates(int[] integers) {
  75.         int[] inputWithoutDublicates = new int[integers.length];
  76.         int x = 0;
  77.         boolean nullsInside = false;
  78.         if(countOfDuplicates(integers, 0) != 0){
  79.             nullsInside = true;
  80.         }
  81.  
  82.         for(int value: integers){
  83.             if (countOfDuplicates(inputWithoutDublicates, value) == 0){
  84.                 inputWithoutDublicates[x] = value;
  85.                 x += 1;
  86.             }
  87.             if ( value == 0 && nullsInside){
  88.                 inputWithoutDublicates[x] = value;
  89.                 x += 1;
  90.                 nullsInside = false;
  91.             }
  92.  
  93.         }
  94.  
  95.         int[] result = new int[x];
  96.         for (int j = 0; j < x; j++){
  97.             result[j] = inputWithoutDublicates[j];
  98.         }
  99.         return  result;
  100.     }
  101.  
  102.     public static int countOfDuplicates(int[] input, int x){
  103.         int count = 0;
  104.         for(int symbol : input){
  105.             if(symbol == x){
  106.                 count += 1;
  107.             }
  108.         }
  109.         return count;
  110.     }
  111.  
  112.     public static int sumIgnoringDuplicates(int[] integers) {
  113.         int result = 0;
  114.         int[] arr = removeDuplicates(integers);
  115.         for (int x : arr){
  116.             result += x;
  117.         }
  118.  
  119.         return result;
  120.     }
  121.  
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement