Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Main {
- public static void main(String[] args)
- {
- char[] arr1 = {'d', 's', '$', '$', '$', '4', 's', 'd' };
- char[] arr2 = {'a', 'b', 'c', '$', 'a', 'x', 'y', '$', 'b', 't', 'd', '$', 'v' };
- System.out.println(isDollarChain(arr1, 3));
- System.out.println(isDollarChain(arr2, 9));
- }
- public static boolean isDollarChain(char[] arr, int len)
- {
- int chars_counter = 0;
- int dollar_counter = 0;
- for (int i = 0; i < arr.length; i++)
- {
- if (dollar_counter == 0)
- {
- if (arr[i] == '$')
- {
- chars_counter++;
- dollar_counter++;
- }
- else
- {
- continue;
- }
- }
- else // we had one $ already, so we start counting characters
- {
- chars_counter++;
- if (arr[i] == '$')
- {
- dollar_counter++;
- if (dollar_counter == 3)
- {
- if (len == chars_counter)
- return true;
- else
- return false;
- }
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement