Android System.out.println()输出到TextArea
我有一个问题,如何将Android System.out.println()输出到TextArea,android,textarea,Android,Textarea,我有一个问题,如何将System.out.println()以数组形式输出到Eclipse项目界面中的TextArea 我使用java中的普林斯顿FFT算法使用System.out.println()方法得出公式的结果。 代码如下: public class FFT { // compute the FFT of x[], assuming its length is a power of 2 public static Complex[] fft(Complex[] x) { int
System.out.println()
以数组形式输出到Eclipse项目界面中的TextArea
我使用java中的普林斯顿FFT算法使用System.out.println()
方法得出公式的结果。
代码如下:
public class FFT {
// compute the FFT of x[], assuming its length is a power of 2
public static Complex[] fft(Complex[] x) {
int N = x.length;
// base case
if (N == 1) return new Complex[] { x[0] };
// radix 2 Cooley-Tukey FFT
if (N % 2 != 0) { throw new RuntimeException("N is not a power of 2"); }
// fft of even terms
Complex[] even = new Complex[N/2];
for (int k = 0; k < N/2; k++) {
even[k] = x[2*k];
}
Complex[] q = fft(even);
// fft of odd terms
Complex[] odd = even; // reuse the array
for (int k = 0; k < N/2; k++) {
odd[k] = x[2*k + 1];
}
Complex[] r = fft(odd);
// combine
Complex[] y = new Complex[N];
for (int k = 0; k < N/2; k++) {
double kth = -2 * k * Math.PI / N;
Complex wk = new Complex(Math.cos(kth), Math.sin(kth));
y[k] = q[k].plus(wk.times(r[k]));
y[k + N/2] = q[k].minus(wk.times(r[k]));
}
return y;
}
// display an array of Complex numbers to standard output
public static void show(Complex[] x, String title) {
System.out.println(title);
System.out.println("-------------------");
for (Complex x1 : x) {
System.out.println(x1);
}
System.out.println();
}
public static void main(String[] args) {
int N = Integer.parseInt("4");
Complex[] x = new Complex[N];
// original data
for (int i = 0; i < N; i++) {
x[i] = new Complex(i, 0);
x[i] = new Complex(-2*Math.random() + 1, 0);
}
show(x, "x");
// FFT of original data
Complex[] y = fft(x);
show(y, "y = fft(x)");
// take inverse FFT
Complex[] z = ifft(y);
show(z, "z = ifft(y)");
}
}
公共类FFT{
//计算x[]的FFT,假设其长度为2的幂
公共静态复数[]fft(复数[]x){
int N=x.长度;
//基本情况
如果(N==1)返回新的复数[]{x[0]};
//基2 Cooley-Tukey FFT
如果(N%2!=0){抛出新的RuntimeException(“N不是2的幂”);}
//偶数项fft
络合物[]偶数=新络合物[N/2];
对于(int k=0;k
我想在show()
方法中更改System.out.println()
。
请帮助,谢谢。您是想在Android Logcat中记录输出吗?我已经在Netbeans中运行了它,它在控制台中显示了一些值,我想在eclipse中将该值带到我的文本区域,但到目前为止,我还不能,我尝试更改show()方法,但它仍然是一样的