import java.io.*;
public class Class1
{
public static void main (String[] args)
{
int x,y;
String str=" ";
if(args.length < 2)
{
System.out.println("Usage:number1 number2");
System.exit(-1);
}
x=(int) Float.valueOf(args[0]).floatValue( );//在这个位置报强制转化为int.
y=Integer.parseInt(args[1]);
str=str+x+" 的 "+y+" 次方 = "+(Math.pow(x,y));
System.out.println( str );
}
}
public class Class1
{
public static void main (String[] args)
{
int x,y;
String str=" ";
if(args.length < 2)
{
System.out.println("Usage:number1 number2");
System.exit(-1);
}
x=(int) Float.valueOf(args[0]).floatValue( );//在这个位置报强制转化为int.
y=Integer.parseInt(args[1]);
str=str+x+" 的 "+y+" 次方 = "+(Math.pow(x,y));
System.out.println( str );
}
}
在此,属于窄化转换(narrowing conversion),需要使用显式定义。
为何必须使显示转化。莫非还有非窄化转换
danceflash(Wine)他在写文章呢。
java 里int 是32 bit float 是64 bit; 从float 强制转到int 当然就是窄化了。这样做可能会丢失数据信息。慎用啊!
你们都好强啊 ^_^