java 指数怎么表示_Java程序中,表示“数值” 以及 指数表示法 | 学步园

1、表示数值

//: operators/Literals.java

public class Literals {

public static void main(String[] args) {

int i1 = 0x2f; // Hexadecimal (lowercase)

System.out.println("i1: " + Integer.toBinaryString(i1));

int i2 = 0X2F; // Hexadecimal (uppercase)

System.out.println("i2: " + Integer.toBinaryString(i2));

int i3 = 0177; // Octal (leading zero)

System.out.println("i3: " + Integer.toBinaryString(i3));

char c = 0xffff; // max char hex value

System.out.println("c: " + Integer.toBinaryString(c));

byte b = 0x7f; // max byte hex value

System.out.println("b: " + Integer.toBinaryString(b));

short s = 0x7fff; // max short hex value

System.out.println("s: " + Integer.toBinaryString(s));

long n1 = 200L; // long suffix

long n2 = 200l; // long suffix (but can be confusing)

long n3 = 200;

float f1 = 1;

float f2 = 1F; // float suffix

float f3 = 1f; // float suffix

double d1 = 1d; // double suffix

double d2 = 1D; // double suffix

// (Hex and Octal also work with long)

}

} /*

* Output: i1: 101111 i2: 101111 i3: 1111111 c: 1111111111111111 b: 1111111 s:

* 111111111111111

*/// :~

2、表示指数

//: operators/Exponents.java

// "e" means "10 to the power."

public class Exponents {

public static void main(String[] args) {

// Uppercase and lowercase 'e' are the same:

float expFloat = 1.39e-43f;//编译器通常会

expFloat = 1.39E-43f;

System.out.println(expFloat);

double expDouble = 47e47d; // 'd' is optional

double expDouble2 = 47e47; // Automatically double

System.out.println(expDouble);

}

} /*

* Output: 1.39E-43 4.7E48

*/// :~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值