Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package junit;
- public class Code {
- public static void main(String[] args) {
- }
- public static boolean isSpecial(int candidate) {
- return candidate % 11 < 4;
- }
- public static int longestStreak(String inputString) {
- if (inputString == null || inputString.equals("")){
- return 0;
- }
- int longest = 0;
- String lastChar = null;
- int currentStreakLenght = 0;
- for (String currentChar : inputString.split("")) { //abbcccaaaad - делим строку на символы
- if (currentChar.equals(lastChar)) {
- currentStreakLenght++;
- } else {
- currentStreakLenght = 1;
- }
- System.out.println("alksdjlkas");
- if (currentStreakLenght > longest){ //проверка на самое большое число
- longest = currentStreakLenght;
- }
- lastChar = currentChar;
- }
- return longest;
- }
- public static Character mode(String inputString) {
- if(inputString == null){
- return null;
- }
- int modeCount = 0;
- Character mode = null;
- for (char c1 : inputString.toCharArray()){
- int count = 0;
- for (char c2 : inputString.toCharArray()){
- if (c1 == c2){
- count++;
- }
- }
- if (count > modeCount){
- modeCount = count;
- mode = c1;
- }
- }
- return mode;
- }
- public static int getCharacterCount(String allCharacters, char targetCharacter) {
- int count = 0;
- for (Character letter: allCharacters.toCharArray()) {
- if (letter.equals(targetCharacter)) {
- count++;
- }
- }
- return count;
- }
- public static int[] removeDuplicates(int[] integers) {
- int[] inputWithoutDublicates = new int[integers.length];
- int x = 0;
- boolean nullsInside = false;
- if(countOfDuplicates(integers, 0) != 0){
- nullsInside = true;
- }
- for(int value: integers){
- if (countOfDuplicates(inputWithoutDublicates, value) == 0){
- inputWithoutDublicates[x] = value;
- x += 1;
- }
- if ( value == 0 && nullsInside){
- inputWithoutDublicates[x] = value;
- x += 1;
- nullsInside = false;
- }
- }
- int[] result = new int[x];
- for (int j = 0; j < x; j++){
- result[j] = inputWithoutDublicates[j];
- }
- return result;
- }
- public static int countOfDuplicates(int[] input, int x){
- int count = 0;
- for(int symbol : input){
- if(symbol == x){
- count += 1;
- }
- }
- return count;
- }
- public static int sumIgnoringDuplicates(int[] integers) {
- int result = 0;
- int[] arr = removeDuplicates(integers);
- for (int x : arr){
- result += x;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement