Topic: my second program(偶有question!)

  Print this page

1.my second program(偶有question!) Copy to clipboard
Posted by: hitao888
Posted on: 2005-03-06 20:49

public class B001
{
public static void main(String[] args)
{ double a=1.2;
double b=2.4;
double c=2.0;
double x,y,z;
x=a+b;
y=a*c;
z=b/a;
System.out.println("x="+x+" y="+y+" z="+z);
x=a/0;
System.out.println("1.2/0="+x);
x=2/0;
System.out.println("2/0="+x);
}
}//这里有个问题System.out.println("1.2/0="+x); 我不打加号如System.out.println("1.2/0="x); 编译程序告诉我少了‘)’可我明明少了“+”,郁闷!!有时别的程序不输入“+”也行,这是怎么回事!Stupid

2.Re:my second program(偶有question!) [Re: hitao888] Copy to clipboard
Posted by: caoyi
Posted on: 2005-03-07 10:19

因为System.out.println("2/0="+x);的"2/0="已经是字符串了,编译器就认为println方法里面应该存放字符串类型的参数,而你x不是String类型是double类型,所以编译器 认为在字符串和double之间少了一个括号。不知道这个说法对不对。
不加加号的情况我猜不出来,你得把情况说出来,别人才能帮你解决呀


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923