我已经在windows上的eclipse上编写了我的第一个java程序。我最近开始在linux上编程java。java:简单类型转换
当我尝试在Linux上编译上述程序时,它确实工作正常,但是当我尝试在Windows上执行时,出现以下错误。
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from int to short
Type mismatch: cannot convert from double to float
public class TypeDemo {
public static void main (String args[])
{
byte b = 8;
long a = 1000011334;
int c = 76;
short s = 99789;
float f = 99.99;
double d = 99979.9879;
boolean bool = true;
char ch = 'y';
System.out.println ("b = "+b);
System.out.println ("a = "+a);
System.out.println ("c = "+c);
System.out.println ("s = "+s);
System.out.println ("f = "+f);
System.out.println ("d = "+d);
System.out.println ("bool = "+bool);
System.out.println ("ch = "+ch);
}
}
如果有的话,这段代码在Linux上编译很奇怪。你使用什么编译器?它真的是完全相同的代码吗? – Dolda2000