Java 学习中的问题


 

最后t的值是什么(-23)

解释:

因为由int转换成byte类型时

因为n在内存中存储为:0000 0000 0000 0000 0000 0000 1110 1001

转换成byte类型后:                                                          1110 1001

因为左边第一个为符号位,为负数  并且计算机在存储是用的是补码形式,所以

由补码转换成原码为:1001 0111

所以结果是-23

 

 

     int decVal = 26; 	   // The number 26, in decimal
     int octVal = 032; 	   // The number 26, in octal
     int hexVal = 0x1a;	   // The number 26, in hexadecimal
     int binVal = 0b11010; // The number 26, in binary

You can place underscores only between digits; 
you cannot place underscores in the following places:

At the beginning or end of a number
Adjacent to a decimal point in a floating point literal
Prior to an F or L suffix
In positions where a string of digits is expected
The following examples demonstrate valid 
and invalid underscore placements in numeric literals:

float pi1 = 3_.1415F;      // Invalid; cannot put underscores adjacent to a decimal point
float pi2 = 3._1415F;      // Invalid; cannot put underscores adjacent to a decimal point
long socialSecurityNumber1
  = 999_99_9999_L;         // Invalid; cannot put underscores prior to an L suffix

int x1 = _52;              // This is an identifier, not a numeric literal
int x2 = 5_2;              // OK (decimal literal)
int x3 = 52_;              // Invalid; cannot put underscores at the end of a literal
int x4 = 5_______2;        // OK (decimal literal)

int x5 = 0_x52;            // Invalid; cannot put underscores in the 0x radix prefix
int x6 = 0x_52;            // Invalid; cannot put underscores at the beginning of a number
int x7 = 0x5_2;            // OK (hexadecimal literal)
int x8 = 0x52_;            // Invalid; cannot put underscores at the end of a number

int x9 = 0_52;             // OK (octal literal)
int x10 = 05_2;            // OK (octal literal)
int x11 = 052_;            // Invalid; cannot put underscores at the end of a number

class PrePostDemo {
     public static void main(String[] args){
          int i = 3;
	  i++;
	  System.out.println(i);	// "4"
	  ++i;			   
	  System.out.println(i);	// "5"
	  System.out.println(++i);	// "6"
	  System.out.println(i++);	// "6"
	  System.out.println(i);	// "7"
     }
}


class BitDemo {
     public static void main(String[] args) {
          int bitmask = 0x000F;
	  int val = 0x2222;
	  System.out.println(val & bitmask);  // prints "2"
     }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值