import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.applet.Applet;
import java.util.Scanner;
public class Histogram extends Applet{
static int [] scores= {13,30,23,8};
static int [] minInterval = {0,25,50,75};
static int [] maxInterval = {25,50,75,100};
public void paint (Graphics g){
int max = 0;
for (int i = 0; i < scores.length; i++) {
if (max < scores[i]) {
max = scores[i];
}
}
Graphics2D g2 = (Graphics2D)g;
Point2D.Double Yi = new Point2D.Double(50,50);
Point2D.Double Yf = new Point2D.Double(50,30*scores.length);
Line2D.Double Y = new Line2D.Double (Yi,Yf);
Point2D.Double Xi = new Point2D.Double(50,50);
Point2D.Double Xf = new Point2D.Double(50+(8*max),50);
Line2D.Double X = new Line2D.Double (Xi,Xf);
int x = 8*max;
//Draw the "Score"
int headerX = 50+(x/(max/5))*((max/5)-1);
g2.drawString("Histogram of Student Scores",(headerX),30);
for(int i=0;i<=max/5;i++){
int j = (i)*5;
if(i<max/5)
g2.drawString(String.format("%d",j),50+(x/(max/5))*i,50);
else
g2.drawString(String.format("Number of Students"),50+(x/(max/5))*i,50);
}
for(int i=0;i<=maxInterval.length;i++){
if(i != maxInterval.length-1)
g2.drawString(String.format("[%d,%d)",minInterval,maxInterval),20,60+(30)*i);
else if(i == maxInterval.length-1)
g2.drawString(String.format("[%d,%d]",minInterval,maxInterval),20,60+(30)*i);
else
g2.drawString("Score Ranges",20,60+(30)*i);
}
g2.draw(X);
g2.draw(Y);
}
}
我的問題是代碼當我測試在另一我的代碼不會在循環執行的代碼塊
方法中的循環不進入第三loop.but。它有點工作,所以我不知道接下來要做什麼。我想知道它爲什麼不是
執行該代碼塊。
提前致謝。
你怎麼知道它不執行第二個循環? – vandale
我會使用一個調試器 - 將一些中斷點加入並看看發生了什麼。這比在這裏要求更快,除非你有一個SSCCE。 –
你可以在該行確認max> 0嗎? –