Dhara Padia
BAN USERpublic void squareArray(int[] inputArray)
{
int length = inputArray.length;
for(int i = 0 ;i < length; i++)
{
inputArray[i] = inputArray[i] * inputArray[i];
}
System.out.print(Arrays.toString(inputArray));
}
public String printString(String input, String alphabet)
{
String result = "";
int length = alphabet.length();
// ^ matches the start of the string
// (?: open a non capturing group
// ([alphabets]) The characters that are allowed the found char is captured in group 1
// (?!.*\\1) That character is matched only if it does not occur once more
// ){length} Defines the amount of characters
// $ matches the end of the string
String REGEX = "^(?:([" +alphabet + "])(?!.*\\1)){" + (length) +"}$";
Pattern p = Pattern.compile(REGEX);
int inputLength = input.length();
for(int i = 0 ; i < (inputLength - length + 2);i++)
{
result = input.substring(i, i+length);
if(p.matcher(result).find())
{
return result;
}
}
return result;
}
public void sortArraySample(int[] arr){
// move non-zero numbers at the start of the array
// if array element which contains 0 is moved to start of the array increment j by 1
int j = 0;
int length = arr.length;
for(int i = 0 ; i < length; i++)
{
if(0 == arr[i])
{
// temporary variable for swaping values.
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
j++;
}
}
}
- Dhara Padia February 07, 2017