code for buildShortArray for audiomixing [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to android and i just want to create a dj player. but for that the starting step is mixing two files. The rough code for that i found on the following link but in that i did not understand how to code for buildShortArray(music1).
I already tried this code but got stuck in the above mentioned method's code.
thank you in advance for help.
Docs here:Mix two files audio wav on android use short array

The code from the link does not show the buildShortArray method.
You need to transform List<Short> into array short[]:
List<Short> music1 = ...;
short[] arrayMusic1 = buildShortArray(music1);
You could write the method buildShortArray like this:
public short[] buildShortArray(List<Short> list) {
short[] array = new short[list.size()];
for(int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
return array;
}
However, i'd like to warn you, copy-pasting code is never a good idea.

Related

How to use System.out.print(Arrays.toString(a)) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How to use it and an example with that please. Thanks! If you could also, I want a program that prints an array. I can't do it beaucause it makes me an error, and I want to know if I do something wrong.
Is that code right??
import java.util.Arrays;
kk
I get this:
I
I
[[I#e53108, [I#f62373]I
I
[[I#e53108, [I#f62373]
Osama, when I run your code, there pop ups an error box which says java exception and prints many errors.
Osama, your code when I run it says java Exception in an error box
I get this: I I [[I#e53108, [I#f62373]I I [[I#e53108, [I#f62373]
This is because you are printing a multi-dimensional array. For this, you can use Arrays#deepToString():
System.out.print(Arrays.deepToString(a));
A simple program to print an Array of string values
public class PrintArray{
public static void main(String[] args){
String[] array = {"a","b","c","d"};
for(String s : array)
System.out.println(s);
}
}
the output:-
a
b
c
d
I hope it's useful for you.

Why Random random = new Random()? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi guys rather new to java, I am just having a bit of problem understanding some of the basics.
When you declare a random value you use Random random = new Random(), can someone please explain what the first Random, second random and "new Random()" does and the logic behind it?
Just a note, the first commenter is correct, you probably could have found this through a bit of Googling, but here's the answer as best as I can explain it:
Let's take that code:
Random random = new Random();
The first random just says what type of data the variable is going to store - in this case, "Random." The second random is the name of the variable. You can call this almost anything you want, "random," "ran," even something completely unrelated like "ThisIsAVar." Then you set the new variable (using the "=") to a new Random type.
A more generic example would be (as "Random" in the last explanation messes with the grammar):
string NewString = new String("Hello there!");
You're creating a new variable called NewString with type of string, and setting that to a new String type with the parameter "Hello there!"

Why can this not be done? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to shorten my code using a loop. I have for example 5 zombies in my game. So I thought I could do this
Image zombie;
for(int i = 0; i < 5; i++){
if (zombie.getZombieRect().intersects(zombie + i + .getZombieRect())) {
}}
Why can this not be done? adding i to the end of zombie. zombie being an image. The oother variables are zombie1, zombie2 etc.
Thanks for all help.
This is what arrays are for:
Zombie zombies[] = {zombie, zombie1, zombie2, zombie3, zombie4};
for (int i = 0; i < zombies.length; i++) {
if (zombie.getZombieRect().intersects(zombies[i].getZombieRect())) {
}
}
Make an Array of Objects and then u can call them by using zombie[i] etc whatever you want to do.
The thing of adding you are trying to do is suitable in case of strings only
"zombie"+i;
etc.
To answer the question,
zombie + i
Is a compile-time error because java does not allow an Image object to be used in combination with an int in the '+' operator.

Sample Java code to simulate out of memory situation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am basically a Weblogic admin and want to simulate out of memory situation through deploying a very simple Java code(war/ear file) in my Weblogic instance.
I have a very little knowledge about Java coding so can someone please provide me a sample code which I can easily pack as war and deploy?
This should be enough:
long[][] ary = new long[Integer.MAX_VALUE][Integer.MAX_VALUE];
This will try to allocate 2^31 + 1 memory blocks, each of size 2^34 bytes.
You can do final long[] l = new long[Integer.MAX_VALUE]; It will allocate 16Gb - 8 bytes.
Or you can just throw new OutOfMemoryError();
To simulate the memory being consumed over time try:
List<long[]> list = new LinkedList<long[]>();
while (true) {
list.add(new long[65536]); // an arbitrary number
// sleep(1) perhaps?
}

Check if all chars match? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Basically, I have to write a method that determines whether all the characters in a string are the same, using only library String methods.
Use matches. Please read up the documentation of Pattern class to understand how to use matches function to check your input. It is quite useless for me to give you a straight answer, since you don't learn much from it.
That method will give you one-liner solution after you have understood regex.
public static void main(String[] args) {
String str = "aaaaa";
int count = str.length() - str.replaceAll(String.valueOf(str.charAt(0)), "").length();
if(count == str.length())
System.out.println("All characters in a given String are same");
}
Try this : This is the simplest and best solution for this kind of problem.
One way to solve this is without looping or recursion is by [ab]using String.replace1.
The actual implementation is left as an exercise.
1 It does not require that your code loops, but something must loop.

Categories