问答题
下面是一个字符界面的Java Application程序,它接受用户输入的一个浮点数,并将它的整数部分和小数部分分别输出。请勿改动原有代码,在下画线处填人适当语句,将程序补充完整。
import java.io.*;
public class test16_2
public static void main(String args[])
String s;
double d;
int i;
boolean b=false;
do
try
System.out.println("请输入一个浮点数:");
BufferedReader br=
new BufferedReader(new lnputStreamReader(System.in));
s=br.readLine();
i=s.indexOf( );
d=__________.parseDouble(s);
System.out.println(d+"整数部分为:"+__________);
if(i==-1)
System.out.println(d+"小数部分为:0.0");
else
System.out.println(d+"小数部分为:"
+Double.parseDouble(
((s.charAt(0)==’-’)"-":"")
+"0."+s.substring(i+1,s.length())));
b=false;
catch(NumberFormatException nfe)
System.out.prinfln("输入浮点数格式有误。\n");
b=true;
catch(IOException ioe)
b=false;
while(b);
【参考答案】
Double
(long)d
热门
试题
问答题
下面是一个Applet程序,其功能是用一组坐标点绘制一个多边形,并通过沿坐标的垂直方向移动,把它移到窗口的下半部分,然后填充它。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 import java.awt.*; import java.applet.*; * <applet code= ex16_3.class width=800 height=400> < applet> * public class ex16_3 extends Applet int[] x=15,50,100,160,120,190; int[] y=15,100,30,15,80,50 ; public void init() setBackground(Color.lightGray); public void paint(Craphics g) int[]y2=new int[6]; g.setColor(Color.red); Rectangle rect=getBounds(); g.drawPolygon(x,y2,6); for(int i=0;i<6;i++) Y2[i]=y[i]+(rect.height 2); g.fillPolygon(x,y,6); ex16_3.html <HTML> <HEAD> <TITLE>ex16_3< TITLE> < HEAD> <BODY> <applet code=’ex16_3.class width=800 height=400> < applet> < BODY> < HTML>