问答题

下列程序中,分别计算1,2,3......,10的阶乘,并输出计算结果,请将程序补充完整。
程序运行结果如下:
1!=1
2!=2
3!=6
4!=24
5!=120
6!=720
7!=5040
8!=40320
9!=362880
10!=3628800
public class ex10_1
public static void main(String[]args)
long 1 Factorial;
for(int i=1;i<=10;i++)
_____________;
for(int j=2;___________;j++)
_____________;
System.out.println(i+ " ! =" + 1Factorial);


【参考答案】

1Factorial=1
j<=i
1Factorial*=j
热门 试题

问答题
下面是一个Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,点击按钮,可以在文本区已有的文本基础上追加显示10条“Welcome to the NCR Examination!”信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下: import javax.swing.* ; import java.awt.*; import java.awt.event.*; * <applet code= ex10_3.class width = 800 height=400> < applet> * public class ex10_3 extends JApplet JButton jb = new JButton( Add Text ); JTextPane itp = new JTextPane(); public void init() jb.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) for(int i = 1;i<10;i++) jtp.getText(jtp.setText()+ Welcome to the NCR Examination! n ); ); Container cp = getContentPane(); cp.add(new JScrollPane(jtp)); cp.add(BorderLayout.SOUTH,jtp); public static void main(String[]args) ex10_3 obj10_3=new ex10_3(); String str = obj10_3.getClass().toString(); if(str.indexOf( class ) != -1) str = str.substring(6); JFrame frm = new JFrame(str); frm.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent we) System.exit(O); ); frm.getContentPane().add(ex10_3); frm.setSize(300, 400); frm.setVisible(true); ex10_3.html <HTML> <HEAD> <TITLE>ex10_3< TITLE> < HEAD> <BODY> <applet code= exl0_3.class width=800 height=400 > < applet> < BODY> < HTML>