问答题

本题程序的功能是随机产生50个0~100间的随机数,并计算70~80间随机数的个数(包括70,不包括80)。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
public class basic

public static void main(String[] args)

int result = 0;
int i = 0;
int randomNum;
while (i<50)

randomNum =______;
if(______)
result ++;
______;

System.out.println("result =" + result);

【参考答案】

(int)(Math.random()*100)。
randomNum>=70&&randomNum<80。
i++。
热门 试题

问答题
本题程序的功能是通过滑动条修改颜色的RGB值,从而控制颜色。程序中有一个面板、3个标签和3个滑动条,标签和滑动条一一对应,分别对应三原色红、绿、蓝,任意拖动其中的一个滑动条,所对应的颜色值就会发生变化,面板的颜色也会对应地发生变化。滑动条值的范围是0~255。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class simple extends JFrame implements AdjustmentListener public simple() setTitle( simple ); setSize(300,200); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit (0); ); Container contentPane =______; JPanel p = new JPane1(); p.setLayout(new GridLayout(3,2)); p.add(redLabel = new JLabel( Red 0 )); p.add(red = new JScrollBar(Adjustable.HORIZONTAL,0,0,0,255)); red.setBlockIncrement(16); red.addAdjustmentListener(this); p.add(greenLabel = new JLabel( Green 0 )); p.add(green = new JScrollBar(Adjustable.HORIZONTAL,0,0,0,255)); green.setBlockIncrement(16); green.addAdjustmentListener(this); p.add(blueLabel = new JLabel( Blue 0 )); p.add(blue = new JScrollBar(Adjustable.HORIZONTAL,0,0,0,255)); blue.setBlockIncrement(16); blue.addAdjustmentListener(this); contentPane.add(p, South ); colorPanel = new JPanel(); colorPanel.setBackground(new Color(0,0,0)); contentPane.add(colorPanel, Center ); public void adjustmentValueChanged(AdjustmentEvent evt) redLabel.setText( Red + red.getValue()); greenLabel.setText( Green + green.getValue()); blueLabel.setText( Blue + blue.getValue()); colorPanel.setBackground(new Color(red.getValue().green.getValue(),blue.getValue())); ______; public static void main(String[] args) JFrame f = new simple(); f.show(); private JLabel redLabel; private JLabel greenLabel; private JLabel blueLabel; private JScrollBar red; private JScrollBar green; private JScrollBar blue; private JPanel colorPanel;