问答题
本题中定义了长度为20的一维整型数组a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。
public class java1(
public static void main(String[]args){
int a[]=______;
int i;
for(______;i++)
a[i]=i;
for(i=0;i<20;i++){
if(______)
System.out.print("a["+i+"]="+a[i]+",");
}
}
【参考答案】
第1处:new int[20]
第2处:i=0;i<20
第3处:i%2! =0[解析] 第1处定义......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
点击查看答案
<上一题
目录
下一题>
热门
试题
问答题
下面是一个Applet程序,其功能是从3~100之间(包括3和100)每隔0.5秒显示一个新的数字,如果数字为素数,则显示为灰色,其他为绿色。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下:import java.awt.*;import java.applet.Applet; *<applet code=ex15_3.class width=800 height=400>< applet>* public class ex15_3 extends Applet{public Color color15_3 = Color.black;private int n15_3 = 3;public myPrime thPrime15_3;public void init(){thPrime15_3 = new myPrime(this);thPrime15_3.start();}public void paint(Graphics g){g.setColor(color15_3);g.drawString(n15_3, 50, 50);}public int getInt(){return n15_3;}public void setInt(int i){n15_3=i;}}class myPrime extends Thread{ex15_3 obj15_3;myPrime (ex15_3 o){this.obj15_3 = o;}public boolean isPrime(int n){boolean bPrime = true;int i=2;if(n<3||n>100)return false;while(i<n-1&&bPrime){if ((n % i) == 0)bPrime = false;i++;}return bPrime;}public void run(){int i;for (i=3;i<100; i++){if (isPrime(i))obj15_3.color15_3 = Color.gray;elseobj15_3.color15_3 = Color.green;obj15_3.n15_3;obj15_3.repaint();try{sleep(500);}catch (InterruptedException ie)____}}}ex15_3.html<HTML><HEAD><TITLE>ex15_3< TITLE>< HEAD><BODY><applet code= ex15_3.class width=800 height=400>< applet>< BODY>< HTML>
点击查看答案
问答题
请完成下列Java程序:制作一个图形用户界面,上方包含一个TextField和Button构件,实现输入字符串,点击Button获取文本区的字符:中间显示Label的内容:下方是4个按钮,分别实现控制Label在最左边,在中间,在右边和退出程序的功能。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;public class ex15_2 extends Frame implements ActionListener {private Label 1;private TextField tf;public static void main(String[] args) {ex15_2 obj15_2 = new ex15_2();}public ex15_2() {setBackground(Color.gray);l = new Label( Welcom to the NCR Examination! );Font font = new Font( TimesRoman ,Font.BOLD,20);l.setFont(font);add( Center ,l);Panel p = new Panel();Button b = new Button( Left );b.addActionListener(this);p.add(b);b = new Button( Center );b.addActionListener(this);p.add(b);b = new Button( Right );b.addActionListener(this);p.add(b);________________;b = new Button( Exit );b.addActionListener(this);p.add(b);p = new Panel();tf = new TextField(40);p.add(tf);b = new Button( Set );b.addActionListener(this);p.add(b);add( North ,p);setSize(500,300);show();}public void actionPerformed(ActionEvent ae) {if(ae.getActionCommand().equals( Exit ))System.exit(0);else if(ae.getActionCommand().equals( Left ))____________________; else if(ae.getActionCommand().equals( Center )l.setAlignment(Label.CENTER);else if(ae.getActionCommand().equals( Right ))l.setAlignment(Label.RIGHT);else if(ae.getActionCommand().equals( Set ))l.setText(tf.getText());}}
点击查看答案
相关试题
下面是一个Applet程序,其功能是从3~10...
请完成下列Java程序:制作一个图形用户界面...