【发布时间】:2014-07-25 18:22:44
【问题描述】:
我知道网上还有这样的问题,但我的代码无法正常工作。我不知道我的 if 语句是否不正确或是否有其他问题。这是我之前问题的延伸 Remove duplicates in a 2D array and add the corresponding values
问题仍然相同,但除了使用 for 循环而不是使用 2D 数组之外,我不想跟踪 for 循环中以前的数字,但是当我将数字打印到控制台时,我获得重复的 r 值。我希望有人可以帮助我看到错误。提前致谢!
这是我正在处理的代码:
double rMax = -1;
double previous;
for(int i =1; i< 256; i++){
for(int y =1; y< 256; y++){
//image.getPixel(i, y);
String x = image.getLocationAsString(i, y);
String n = image.getValueAsString(i, y);
String delim = ", value=";
String [] tokens = n.split(delim);
double num = Double.parseDouble(tokens[1]);
//if(image.getR() < 1.43){
String [] t = x.split("r=");
String[] b = t[1].split(" mm/c");
//System.out.print("Meet b: "+b[0]);
double radius = Double.parseDouble(b[0]);
String [] theta = x.split("theta= ");
String [] token2 = theta[1].split(Character.toString(IJ.degreeSymbol));
float thetaNum = Float.parseFloat(token2[0]);
//System.out.print(" This is the theta value: "+thetaNum+" ");
if(radius == rMax){
rMax = radius;
}
String prevX = image.getLocationAsString(i-1, y-1);
String prevN = image.getValueAsString(i-1, y-1);
String [] prevT = prevX.split("r=");
String[] prevB = prevT[1].split(" mm/c");
//System.out.print("Meet b: "+b[0]);
double prev_radius = Double.parseDouble(prevB[0]);
previous = prev_radius;
if(previous == radius){
System.out.println(radius);
}
else{
System.out.println(radius);
}
//if(thetaNum <= 180.00){
data.add(radius, num);
//}
//}
}
}
System.out.println(rMax);
这是打印出来的:
1.59
1.59
1.58
1.58
1.57
1.56
1.56
1.55
1.55
1.54
1.54
1.53
1.52
1.52
【问题讨论】:
标签: java loops duplicates