I'm trying to compare elements of an array of ints 8 elements long (array[]) add up the elements in sets of 2, then divide by 2 for the avg, eg array[0] + array[1] / 2 and assign the result to a new array 4 elements long.. Specifically, I want to compare them in sets of 2 to see if either / or both are less than 40, if either is less than 40, I add them both up and divide by 2 for the average, and assign the array with the minimum out of (40, array[i]).. however if they are both above 40 I still add both elements and divide by 2 but assign the array element[i] with the number I get, not bothering with a minimum calculation
Heres what I have so far
for (int i = 0; i < array.length ; i++)
{
if (array[i] < 40 )
{
array2[j] = Math.min(35, array2[j]);
}
}
The if statement is correct I think, but the boolean argument is far from it. Array[] = the original 8 element array... array2[] = the calculated and averaged array 4 elements long. Many thanks
Is this what you mean? Hopefully I understood the question.
for (int j = 0; j < array2.length; j++)
{
double avg = (array[2 * j] + array[2 * j + 1]) / 2;
if (array[2 * j] < 40 || array[2 * j + 1] < 40)
{
array2[j] = Math.min(avg, 40);
} else {
array2[j] = avg;
}
}
I think this captures the logic you described(?)
int[] test = {
22,44,
52,36,
35,41,
63,24
};
double[] newarr = new int[test.length/2];
for (int i = 0; i < newarr.length; i++){
newarr[i] = (test[i*2] + test[i*2+1]) / 2;
}
Gives:
[33.0, 44.0, 38.0, 43.5]
Correct?
Related
So, for example i have an array: int[] {1,2,3,4,5}. I need to print the product of even positions, 0 position will be considered even, so it will be: 1 * 3 * 5 = 15.
When I am summing an array, I am doing something like this:
int sum = 0;
for (int i = 0; i < arr.length; sum += arr[i++])
and I am receiving the answer correct.
Now, I thought of using the same method for getting the product:
int produs = 1;
for (int i = 0; i < arr.length; produs *= arr[i = i + 2])
Here I always get an error. I don't know why, but if I am doing:
int produs = 1;
for (int i = 0; i < arr.length; i++) {
if ( (i & 1) == 0) {
produs *= arr[i];
}
}
or
int produs = 1;
for (int i = 0; i < arr.length; i = i + 2) {
produs *= arr[i];
}
I am also getting correct answer.
so, my question is why my method with inline for does not work?
int produs = 1;
for (int i = 0; i < arr.length; produs *= arr[i = i + 2])
this one.
If you perform a suffix increment operation, the compiler puts the old value on the stack, e.g.
int[] arr = new int[] { 0, 10, 20, 30 };
int i = 0;
int x = arr[i++]; // x will be 0, i is incremented to 1
On the other hand, if you would use a prefix increment operation, the compiler puts the new value on the stack, e.g.
int[] arr = new int[] { 0, 10, 20, 30 };
int i = 0;
int x = arr[++i]; // x will be 10, i is incremented to 1
Lastly, a variable assignment operation puts the resulting value on the stack, e.g.
int[] arr = new int[] { 0, 10, 20, 30 };
int i = 0;
int x = arr[i = i + 3]; // x will be 30, i is increased by 3
Therefore, if you use arr[i = i + 2] as post-block statement, you actually access the following array elements: 2, 4, 6, yielding an ArrayIndexOutOfBoundsException.
I strongly recommended (also for the sake of readability) that you restructure your algorithm to use the for-block to do the actual calculation and to use the post-block statement to increase the variable i:
for (int i = 0; i < arr.length; i+=2) {
// TODO Calculation
}
You run into an ArrayIndexOutOfBoundsException, because you try to access an element beyond the array boundary. That is because the condition i < arr.length will not be checked when you do produs *= arr[i = i + 2] in the last section of the for-loop.
You can just split up your code inside the increment section, in fact you can chain as many statements in there as you wish, you just have to separate them with a comma ,:
int produs = 1;
for (int i = 0; i < arr.length; produs *= arr[i], i += 2);
The reason you cannot implement a for-loop like this inline is that in the incremental part produs *= arr[i = i + 2] you will have i reaching an index out of the bound of your array because it jumps through 2 steps. Basically in its final iteration, i will reach value of 6 which is out of the indices of your array (the final index of your array is 4) and the part produs *= arr[i = i + 2] will produce an error.
In this case, it is better to use the way that worked for you:
int produs = 1;
for (int i = 0; i < arr.length; i = i + 2) {
produs *= arr[i];
}
You always instantiate your produs with 0.
If you multiply something with zero, than it will be zero.
You have to instantiate it with 1, then should your last example work
int produsOfEven(int[] array) {
int produs = 1;
// step by 2
for (int i = 0; i < array.length; i += 2) {
produs *= array[i];
}
return produs;
}
Edit
To your question, why the last example wont work: As already pointed out in the comments, your condition will be checked to "late".
Let us imagine you have the code for (int i = 0; i < arr.length; produs *= arr[i = i + 2]) and array of length 3. Then this steps will be computed:
Init i with 0.
Check condition i < arr.length, it is true.
Exec body - no body, nothing will happen.
Increase i by running produs *= arr[i = i + 2], i is now 2, produs is changed by array-index 2.
Check condition i < arr.length, it is true.
Exec body - no body, nothing will happen.
Increase i by running produs *= arr[i = i + 2], i is now 4, produs is changed by array-index 4. ArrayIndexOutOfBoundsException was thrown.
You had better use stream
java.util.concurrent.atomic.AtomicInteger index = new java.util.concurrent.atomic.AtomicInteger();
int produs = java.util.Arrays.stream(new int[] {1,2,3,4,5})
.filter(i -> index.getAndIncrement() % 2 == 0).reduce(1, (a, b) -> a * b);
I have a problem with my Java code... I've been staring at it for over 10 hours now and I am just not able to find the mistake(s) I made.
My task was to implement the "median of medians"-algorithm, by splitting an array into arrays of maximum length 5 and look for their median. Then you look up the median of these medians and split your main-array into two parts, one with the smaller values and one with the bigger values. By the length of these arrays, you can now decide in which array you have to look for what position and then repeat the algorithm or finish if both arrays have the same size.
But somehow in most cases, my algorithm is one or two positions away from the correct result. So I think, that there is a small mistake somewhere, probably just with the range of a loop or something like this. So e.g. I tested the array {0,1,2,3,4,5,6,7,8} so the median is 4, but my program responds with 3 as the result.
I am absolutely aware, that this is a whole lot of code and my question might be not exactly what StackOverflow is there for. Also in most cases, I don't prefer letting other people look over my code, but I am desperate because I am not able to somehow find the mistake(s) I made. So I would be really thankful if somebody of you guys could look over it from a neutral position and maybe give me a small hint why it is not working in the way it should.
Thanks a lot
import java.util.Arrays;
public class MedianSelector {
/**
* Computes and retrieves the lower median of the given array of pairwise
* distinct numbers using the Median algorithm presented in the lecture.
*
* #param numbers array with pairwise distinct numbers.
* #return the lower median.
* #throw IllegalArgumentException if the array is {#code null} or empty.
*/
public static int lowerMedian(int[] numbers) {
// look out for wrong input
if (numbers == null || numbers.length == 0) {
throw new IllegalArgumentException("Input is not correct");
}
if (numbers.length == 1) {
return numbers[0];
}
return getValueAtPosition(numbers, ((numbers.length + 1) / 2) - 1);
}
private static int getValueAtPosition(int[] numbers, int positionI) {
// if the array is smaller then 6 elements
// find median immediately
if (numbers.length <= 5) {
return smallArraySort(numbers);
}
// splitting the array into small arrays of maximum size 5
int fields = 0;
// checking if the array is split-able in only arrays of length 5
// if not, then put the remaining values into an array of size <5
if (numbers.length % 5 == 0) {
fields = numbers.length / 5;
} else {
fields = numbers.length / 5 + 1;
}
// creating an array to hold all the smaller arrays
int[][] splitted = new int[fields][];
// filling the array with the smaller arrays if every smallArray has size 5
if (numbers.length % 5 == 0) {
for (int i = 0; i <= splitted.length - 1; i++) {
int[] smallArray = new int[5];
for (int j = i * 5; j < (i + 1) * 5; j++) {
smallArray[j % 5] = numbers[j];
}
splitted[i] = smallArray;
}
} else {
// filling the array with the smallerArrays if the last array is smaller then 5
for (int i = 0; i < splitted.length - 1; i++) {
int[] smallArray = new int[5];
for (int j = i * 5; j < (i + 1) * 5; j++) {
smallArray[j % 5] = numbers[j];
}
splitted[i] = smallArray;
}
int[] smallArray = new int[numbers.length % 5];
for (int j = 0; j < numbers.length % 5; j++) {
smallArray[j] = numbers[(numbers.length) - (numbers.length % 5) + j];
}
splitted[fields - 1] = smallArray;
}
// calculating the median of every small Arrays and writing them into a bigger
// array
int[] medianCollectorArray = new int[fields];
for (int i = 0; i < splitted.length; i++) {
medianCollectorArray[i] = smallArraySort(splitted[i]);
}
// calculating the median of the array of medians recursively
int x = lowerMedian(medianCollectorArray);
// counting the items that are smaller then the median
int counterK = 0;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] < x) {
counterK++;
}
}
// if the position of x is the position we are looking for, then we have found
// the median
if (counterK == positionI) {
return x;
// if the position we are looking for is left from x, we need to repeat the
// algorithm in all elements, that are smaller then x and
// find positionI there
} else if (positionI < counterK) {
int[] L1 = new int[counterK];
int index = 0;
for (int i = 0; i <= numbers.length - 1; i++) {
if (numbers[i] < x) {
L1[index] = numbers[i];
index++;
}
}
return getValueAtPosition(L1, positionI);
} else {
// if the position we are looking for is right from x, we need to repeat the
// algorithm in all elements, that are bigger then x
// and find (positionI - counterK +1) there
int[] L2 = new int[numbers.length - (counterK + 1)];
int index = 0;
for (int i = 0; i <= numbers.length - 1; i++) {
if (numbers[i] > x) {
L2[index] = numbers[i];
index++;
}
}
return getValueAtPosition(L2, positionI - (counterK + 1));
}
}
/**
* This method calculates the median of an array with max. 5 elements.
*
* #param array an array with maximum 5 elements
* #return the median of this array
*/
private static int smallArraySort(int[] array) {
if (array == null || array.length > 5 || array.length <= 0) {
throw new IllegalArgumentException("This array shall not be sorted by this method!");
}
// TODO: IMPLEMENT A SORTING ALGORITHM BY MYSELF
// sorting the array an returning its median
Arrays.sort(array);
return array[(array.length - 1) / 2];
}
}
I think that you dont have to use Integer for these kind of calculations , try using double instead
I think the problem is that you're ignoring positionI when the length of numbers is less than or equal to 5.
You have:
if (numbers.length <= 5) {
return smallArraySort(numbers);
}
I believe this should be:
if (numbers.length <= 5) {
Arrays.sort(numbers);
return numbers[positionI];
}
With just this change your code seems to produce the right answer, at least in all the cases I tried.
Just a small quibble, but this line:
return getValueAtPosition(numbers, ((numbers.length + 1) / 2) - 1);
could be simplified to:
return getValueAtPosition(numbers, (numbers.length - 1) / 2 );
I am stuck on my class work:
Create an application containing an array that stores eight integers. The application should
display all the integers, (done)
display all the integers in reverse order,
display the sum of the eight integers, (done)
display all values less than 5,
display the lowest value, (done)
display the highest value, (done)
calculate and display the average, (Done)
display all values that are higher than the calculated average value.
I must use (or attempt to use) an array; also must use at least one loop to "traverse" (move through) the array. This also due # 23:59 mountain standard time tonight
What am I doing wrong?
package numberlistdemo;
import java.util.Arrays;
public class NumberListDemo
{
/**
* #param args the command line arguments
*/
public static void main(String[] args)
{
int n[]= {1,2,3,4,5,6,7,8};
int lowest = 1000;
int highest = 0;
int sum = 0;
int five = 0;
int OverF = 0;
int rev = 0;
int OverAve= 0;
for (int i=0;i<n.length;i++)
{
int cur = n[i];
if (cur < lowest) lowest = cur;
if (cur > highest) highest = cur;
sum += cur;
}
double ave = sum / n.length;
for (int i=0;i<n.length;i++)
{
int cur = n[i];
if (cur > ave) OverAve = cur;
}
for (int i=0;i<n.length;i++)
{
int LowF = n[i];
if (LowF < 5) five = LowF;
if (LowF > 5) OverF = LowF;
}
//3
System.out.println("Total of the Array is " + sum );
//1
System.out.println("The number we are using are " + Arrays.toString(n));
//4
System.out.println("All values lower the 5 are " + five );
////2
for (int counter=n.length - 1; counter >= 0; counter--)
{
System.out.println("The reverse order of the numbers are " + (n[counter]));
}
//5
System.out.println("The lowest value is " + lowest);
//6
System.out.println("The highest value is "+ highest);
//7
System.out.println("The average is " + ave);
//8
System.out.println("All numbers higher than the average are: " + OverAve);
}
}
I get this
Total of the Array is 36
The number we are using are [1, 2, 3, 4, 5, 6, 7, 8]
All values lower the 5 are 4
The reverse order of the numbers are 8
The reverse order of the numbers are 7
The reverse order of the numbers are 6
The reverse order of the numbers are 5
The reverse order of the numbers are 4
The reverse order of the numbers are 3
The reverse order of the numbers are 2
The reverse order of the numbers are 1
The lowest value is 1
The highest value is 8
The average is 4.0
All numbers higher than the average are: 8
Sample loop to obtain sum, lowest, and highest integer from an array
int lowest = 1000;
int highest = 0;
int sum = 0;
for (int i = 0; i < array.length; ++i) {
int cur = array[i];
if (cur < lowest) lowest = cur;
if (cur > highest) highest = cur;
sum += cur;
}
Edit: the latest code updates made some progress, but likely do not quite meet the specified requirements. There are some difficulties in knowing the full requirement (e.g., output format).
Output Only
The current example is displaying the output (one entry per line). It is not clear if one only needs to display the output or actually reverse the array. If the only requirement is to output the reversal, the numbers larger than 5 and larger than 8, the the following three loops will work. One is mostly already in the suggested code.
System.out.println("The reversed array is: ");
for (int counter < n.length - 1; counter >= 0; counter--) {
System.out.print(n[counter] + " ");
}
System.out.println();
Note that these two should probably be in a method
final int lessThan = 5;
System.out.println("The numbers in the array less than " + lessThan + " are: ");
for (int i = 0; i < n.length; ++i) {
if (n[i] < lessThan) {
System.out.print(n[i] + " ");
}
}
System.out.println();
System.out.println("The numbers in the array greater than the mean " + ave + " are: ");
for (int i = 0; i < n.length; ++i) {
if (n[i] > ave) {
System.out.print(n[i] + " ");
}
}
System.out.println();
Create a new reversed array
It would make more sense for the assignment to require actually reversing the array. In that case, there are a couple of approaches. Probably the easiest is to create a new array and reverse the elements into it. Essentially it is the same loop as above, but placing the elements of n into the array rather than outputing them to the screen. (Note: #Debosmit proposed an example that does not require the additional index variable).
int[] reversed = new int[n.length];
int idx = 0;
for (i = n.length - 1; i >= 0; --i) {
reversed[idx++] = n[i]];
}
Later then one can use the same output approach as was used for displaying all of the original entries:
System.out.println("The reversed array is: " + Arrays.toString(reversed));
What is the error message?
since you are not using curly braces{ } your local variable int i will only exist within these lines:
for (int i=0;i<n.length;i++)
sum = sum + n[i];
and NOT these:
double rev = n.length - i - 1;
boolean l = (n[i] < 5);
Ah! Well... I'll contribute. Here is how to reverse...
// note this will change the original array
for(int i = 0 ; i < n.length ; i++) {
int t = n[i];
n[i] = n[n.length - 1 - i];
n[n.length - 1 - i] = t;
}
// this will not change the original array
int[] newArr = new int[n.length];
for(int i = 0 ; i < n.length ; i++) {
newArr[n.length - 1 - i] = n[i];
}
// you can now return `newArr` or something since it is `n` reversed
Now to look at all values that are higher than the calculated average value. I think you already have the sum of the numbers. Lets call it sum. avg = sum/n.length.
for(int i = 0 ; i < n.length ; i++) {
if(n[i] > avg)
System.out.println(n[i]);
}
All numbers less than 5.
for(int i = 0 ; i < n.length ; i++) {
if(n[i] < 5)
System.out.println(n[i]);
}
In the future, please don't come here with your homework before trying to do it yourself. Thanks! :)
This question already has answers here:
How do I reverse an int array in Java?
(47 answers)
Closed 8 years ago.
I have an array of n elements and these methods:
last() return the last int of the array
first() return the first int of the array
size() return the length of the array
replaceFirst(num) that add the int at the beginning and returns its position
remove(pos) that delete the int at the pos
I have to create a new method that gives me the array at the reverse order.
I need to use those method. Now, I can't understand why my method doesn't work.
so
for (int i = 1; i
The remove will remove the element at the position i, and return the number that it is in that position, and then with replaceFirst will move the number (returned by remove) of the array.
I made a try with a simple array with {2,4,6,8,10,12}
My output is: 12 12 12 8 6 10
so if I have an array with 1,2,3,4,5
for i = 1; I'm gonna have : 2,1,3,4,5
for i=2 >3,2,1,4,5
etc
But it doesn't seem to work.
Well, I'll give you hints. There are multiple ways to reverse an array.
The simplest and the most obvious way would be to loop through the array in the reverse order and assign the values to another array in the right order.
The previous method would require you to use an extra array, and if you do not want to do that, you could have two indices in a for loop, one from the first and next from the last and start swapping the values at those indices.
Your method also works, but since you insert the values into the front of the array, its going to be a bit more complex.
There is also a Collections.reverse method in the Collections class to reverse arrays of objects. You can read about it in this post
Here is an code that was put up on Stackoverflow by #unholysampler. You might want to start there: Java array order reversing
public static void reverse(int[] a)
{
int l = a.length;
for (int j = 0; j < l / 2; j++)
{
int temp = a[j]
a[j] = a[l - j - 1];
a[l - j - 1] = temp;
}
}
int[] reverse(int[] a) {
int len = a.length;
int[] result = new int[len];
for (int i = len; i > 0 ; i--)
result[len-i] = a[i-1];
return result;
}
for(int i = array.length; i >= 0; i--){
System.out.printf("%d\n",array[i]);
}
Try this.
If it is a Java array and not a complex type, the easiest and safest way is to use a library, e.g. Apache commons: ArrayUtils.reverse(array);
In Java for a random Array:
public static void reverse(){
int[] a = new int[4];
a[0] = 3;
a[1] = 2;
a[2] = 5;
a[3] = 1;
LinkedList<Integer> b = new LinkedList<Integer>();
for(int i = a.length-1; i >= 0; i--){
b.add(a[i]);
}
for(int i=0; i<b.size(); i++){
a[i] = b.get(i);
System.out.print(a[i] + ",");
}
}
Hope this helps.
Reversing an array is a relatively simple process. Let's start with thinking how you print an array normally.
int[] numbers = {1,2,3,4,5,6};
for(int x = 0; x < numbers.length; x++)
{
System.out.println(numbers[x]);
}
What does this do? Well it increments x while it is less than numbers.length, so what is actually happening is..
First run : X = 0
System.out.println(numbers[x]);
// Which is equivalent to..
System.out.println(numbers[0]);
// Which resolves to..
System.out.println(1);
Second Run : X = 1
System.out.println(numbers[x]);
// Which is equivalent to..
System.out.println(numbers[1]);
// Which resolves to..
System.out.println(2);
What you need to do is start with numbers.length - 1, and go back down to 0. To do this, you need to restructure your for loop, to match the following pseudocode..
for(x := numbers.length to 0) {
print numbers[x]
}
Now you've worked out how to print, it's time to move onto reversing the array. Using your for loop, you can cycle through each value in the array from start to finish. You'll also be needing a new array.
int[] revNumbers = new int[numbers.length];
for(int x = numbers.length - 1 to 0) {
revNumbers[(numbers.length - 1) - x] = numbers[x];
}
int[] noArray = {1,2,3,4,5,6};
int lenght = noArray.length - 1;
for(int x = lenght ; x >= 0; x--)
{
System.out.println(noArray[x]);
}
}
int[] numbers = {1,2,3,4,5};
int[] ReverseNumbers = new int[numbers.Length];
for(int a=0; a<numbers.Length; a++)
{
ReverseNumbers[a] = numbers.Length - a;
}
for(int a=0; a<ReverseNumbers.Length; a++)
Console.Write(" " + ReverseNumbers[a]);
int[] numbers = { 1, 2, 3, 4, 5, 6 };
reverse(numbers, 1); >2,1,3,4,5
reverse(numbers, 2); >3,2,1,4,5
public int[] reverse(int[] numbers, int value) {
int index = 0;
for (int i = 0; i < numbers.length; i++) {
int j = numbers[i];
if (j == value) {
index = i;
break;
}
}
int i = 0;
int[] result = new int[numbers.length];
int forIndex = index + 1;
for (int x = index + 2; x > 0; x--) {
result[i] = numbers[forIndex--];
++i;
}
for (int x = index + 2; x < numbers.length; x++) {
result[i] = numbers[x];
++i;
}
return result;
}
To clarify, this IS a homework assignment. I'm merely looking for advice, I'm not looking for someone to do my homework for me.
I've already done the first half. It uses two arrays to print an Asterisk design (in this case, the letter 'S'. That works fine. Then, I skip two lines and print the design but flipped (so each line is reversed). It seems to be working fine, but when I run the program, it prints two S's and the second one isn't reversed. Any ideas of what I'm doing wrong?
public class Design {
public static void main (String [] args) {
char [] array = new char [150];
for (int index = 0; index < array.length; index ++)
{
array [index] = '#';
}
int [] indexNumbers = {
0,1,2,3,4,5,6,7,8,9,10,20,30,40,50,
60,70,71,72,73,74,75,76,77,78,79,89,99,109,119,129,139,140,
141,142,143,144,145,146,147,148,149
};
for (int i = 0; i < indexNumbers.length; i++)
{
array [indexNumbers[i]] = ' ';
}
for (int index = 0; index < array.length; index ++)
{
if (index % 10 == 0 && index > 0)
System.out.println();
System.out.print (array[index]);
}
//Now, to reverse the letter
System.out.println();
System.out.println();
int lines = 5;
for (int i = 0; i< array.length; i++){
if (i >= lines)
lines += 10;
char temp = array [i];
array [i] = array [lines - i - 1];
array [lines - i - 1] = temp;
}
for (int index = 0; index < array.length; index ++)
{
if (index % 10 == 0 && index > 0)
System.out.println();
System.out.print (array[index]);
}
}
}
EDIT: Yeah... the design is in spaces, everything else is asterisks.
your reversing is a bit confused.... makes it easier if you do it in two loops.
for (int row = 0; row < (array.Length / 10); row++)
{
for (int col = 0; col < 5; col++)
{
int rowStart = row * 10;
int rowEnd = rowStart + 9;
char temp = array[rowStart + col];
array[rowStart + col] = array[rowEnd - col];
array[rowEnd - col] = temp;
}
}
First, why don't you use String[] or char[][]? Instead you are using a simple array to put multiple lines within. This makes your code confuse and brittle.
To swap an array, the rule is generally simple: Get the first and the last line and swap them. Get the second and the second last, and swap them, get the third and the third last and swap them... Until you get to the middle. This will be much easier if you have an array where each element is a line (like in an String[] or in an char[][]).
If you need to keep the idea of a simple char[] where each 10-char block is a line, simply swap each 10-char block like I stated above.
If you don't want to change the general behaviour of your program, this is the problematic block:
int lines = 5;
for (int i = 0; i< array.length; i++){
if (i >= lines)
lines += 10;
char temp = array [i];
array [i] = array [lines - i - 1];
array [lines - i - 1] = temp;
}
You are not swapping lines here, instead you are swapping chars. This way, your if is not checking and skipping lines, but is instead checking and skipping chars.
This is better:
int lines = array.length / 10;
for (int i = 0; i<= lines / 2; i++){
for (int j = 0; j < 10; j++) {
char t = array[i * 10 + j];
array[i * 10 + j] = array[(lines - i - 1) * 10 + j];
array[(lines - i - 1) * 10 + j] = t;
}
}
So..
First of all, start by printing '#' instead of ' ', and '.' instead of '#'. You will see more clearly what's going on.
Second, you have a problem in the reverse, you are actually not reversing anything, the way you calculate the index lines - i - 1 is wrong. The good way is (i / 10) * 10 + (10 - (i % 10)) -1. Yep, is kinda horrible, but if you want that in one line, using a one-dimension array, there it is. Now it's up to you to understand it, and integrate it in your code ;)