问答题

本题程序随机产生10个学生的成绩(0~100),要求每个学生的成绩都必须及格,同时团体的平均分不少于70分,这样这个团体才能通过,否则就不能通过。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
public class basic

public static void main(String[] args)

int score,sum = 0,i;
for(i = 1;i <= 10; i ++)

score = (int) (______);
System.out.print (score +",");
if(score < 60)
______;
sum = sum + score;
i++;

System.out.println();
if ((i == 10) && (______))
System.out.println("This team passes!");
else
System.out.println("This team doesn’t pass! ");

【参考答案】

Math.random()*100。
break。
(sum/10)>=70。
热门 试题

问答题
本题程序的功能是:主窗口中有两个按钮“Start”和“Close”,单击按钮“Start”后会在窗口左上角生成一个黑色实心小球,小球做斜线运动,碰到面板边缘后反弹几次后停止运动,再次单击按钮“Start”后又会生成一个小球做同样的运动。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; import javax.swing.*; public class advance public static void main (String[] args) JFrame frame = new BounceFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) frame.show(); class BounceFrame extends JFrame public BounceFrame() setSize(WIDTH,HEIGHT); setTitle( advance ); Container contentPane = getContentPane(); Canvas = new BallCanvas(); contentPane.add(canvas,BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); addButton(buttonPanel, Start ,new ActionListener() public void actionPerformed(ActionEvent evt) addBall(); ); addButton(buttonPanel, Close ,new ActionListener() public void actionPerformed(ActionEvent evt) System.exit (0); ); contentPane.add(buttonPanel,BorderLayout.SOUTH); public void addButton(Container c,String title,Listener listener) JButton button = new JButton(title); c.add(button); button.addActionListener(listener); public void addBall() try Ball b = new Ball(canvas); canvas.add(b); for (int i = 1;i <= 1000; i++) b.move (); Runnable.sleep (5); catch (InterruptedException exception) private BallCanvas canvas; public static final int WIDTH = 450; public static final int HEIGHT = 350; class BallCanvas extend JPanel public void add(Ball b) balls.add(b); public void paintComponent(Graphics g) super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; for (int i = 0; i < balls.size(); i++) Ball b = (Ball)balls.get(i); b.draw(g2); private ArrayList balls = new ArrayList(); class Ball public Ball(Component c) canvas = c; public void draw(Graphics2D g2) g2.fill(new Ellipse2D.Double(x,y,XSIZE,YSIZE)); public void move() x += dx; y += dy; if(x < 0) x = 0; dx = -dx; if(x+XSIZE >= canvas.getWidth()) x = canvas.getWidth() - XSIZE; dx = -dx; if(y < 0) y = 0; dy = -dy; if (y+YSIZE >= canvas.getHeight()) y = canvas.getHeight() - YSIZE; dy = -dy; canvas.paint(canvas.getGraphics()); private Component canvas; private static final int XSIZE = 15; private static final int YSIZE = 15; private int x = 0; private int y = 0; private int dx = 2; private int dy = 2;