當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Short intValue()用法及代碼示例

Short類的intValue()方法用於返回Short對象對應的int值。

用法

public int intValue()

參數

不適用

返回值

將 Short 值轉換為 int 類型後返回對應的數值。

例子1

public class ShortIntValueExample1 { 
public static void main(String[] args) { 
 Short sValue = 105; //with positive value 
  // it returns int type value        
int  result = sValue.intValue();  
 System.out.println(" Short "+sValue+" converted into intValue is = " + result); 
 } 
}

輸出:

Short 105 converted into intValue is = 105 

例子2

public class ShortIntValueExample2 { 
public static void main(String[] args) { 
Short sValue = -55; //with Negative value 
 // it returns int type value        
int  result = sValue.intValue();  
 System.out.println(" Short "+sValue+" converted into intValue is = " + result); 
 } 
}

輸出:

Short -55 converted into intValue is = -55






相關用法


注:本文由純淨天空篩選整理自 Java Short intValue() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。