Java入门教程:数据类型举例


  下例中用到了前面提到的数据类型,并通过屏幕显示它们的值。

  public class SimpleTypes{

  public static void main( String args[] ){

  byte b=0x55;

  short s=0x55ff;

  int i=1000000;

  long l=0xfffL;

  char c='c';

  float f=0.23F;

  double d=0.7E-3;

  boolean bool=true;

  System.out.println("b = "+b);

  System.out.println("s = "+s);

  System.out.println("i = "+i);

  System.out.println("c = "+c);

  System.out.println("f = "+f);

  System.out.println("d = "+d);

  System.out.println("bool = "+bool);

  }

  }

  编译并运行该程序,输出结果为:

  C:\>java SimpleTypes

  b = 85

  s = 22015

  i = 1000000

  l = 4095

  c = c

  f = 0.23

  d = 0.0007

  bool = true

相关内容