问答题
下列程序中,要求按照从小到大的顺序输出1~100之间所有能被7整除的数字,请将下列程序补充完整。
注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。
public class Example1_3
public static void main(String[] argv)
int i = 1;
______
if(______)
System.out.print(i+ ",");
______
while(i < 100);
System.out.println();
【参考答案】
①do
②i%7==0
③i++;或者i=i+1;或者i+=1;
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
请完成以下程序,首先由一个类Example2_3实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个Example2_3的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。 注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; class TheSerial implements Serializable private int intValue; private double doubleValue; private String string; TheSerial() intValue = 123; doubleValue = 12.34; string = Serialize Test ; public void setDouble(double d) doubleValue = d; public void setInt(int i) intValue = i; public void setString(String s) string = s; public String toString() return( int= +intValue+ double= +doubleValue+ string= +string); public class Example2_3 public static void main(String argv[]) TheSerial e1 = new TheSerial(); TheSerial e2; try e1.setInt(Integer.parseInt(argv[0])); e1.setDouble(Double.parseDouble(argv[1])); e1.setString[argv[2]); catch(Exception e) e1.setString(e.getMessage)); System.out.println(e1); try FileOutputStream oS = new FileOutputStream( TheSerial.data ); ObjectOutputStream oIS = new ObjectOutputStream(oS); ______; catch(IOException ioException) System.out.println(ioException.getMessage()); try FileInputStream iS = new FileInputStream( TheSerial. data ); ObjectInputStream oIS = new ObjectInputStream(iS); ______ System.out.println(e2); catch(IOException ioException) System.out.println(ioException.getMessage()); catch(ClassNotFoundException cnfException) System.out.println(cnfException.getMessage());
点击查看答案&解析
问答题
在以下程序中,鼠标单击小应用程序的某一点,则会在该点显示一个图标,如果双击,则会清除该图标。且在浏览器的状态栏上会显示鼠标单击位置的坐标。运行结果如下图所示。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不是增行或删行。 import java.applet.*; import java.awt.*; import java.awt.event.*; public class Example3_1 extends Applet int xPoint, yPoint; int sum; Image displayIm; public void init() displayIm = getImage( ms.jpg ); addMouseListener(new SClickMouse()) ; sum = 2; public void paint(Graphics g) if(sum == 1) g.drawImage(displayIm, xPoint, yPoint, this); else g.fillRect(xPoint, yPoint, 60, 60); public class SClickMouse implements MouseListener public void mouseClicked(MouseEvent mouse) sum = mouse.getClickCount(); xPoint = mouse.getX(); yPoint = mouse.getY(); paint(); public void mouseEntered(MouseEvent mouse) public void mouseExited(MouseEvent mouse) public void mousePressed(MouseEvent mouse) xPoint = mouse.getX(); yPoint = mouse.getY(); showStatus( x= +xPoint+ ,y- +yPoint); public void mouseReleased(MouseEvent mouse) Exampie3_1.html: <html> <head><title>Example3_1< title>< head> <body> <applet code= Example3_1.class width= 400 height= 500 > < applet> < body> < html>
点击查看答案&解析
相关试题
请完成以下程序,首先由一个类Example2_...
在以下程序中,鼠标单击小应用程序的某一点...