日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

nextshort_Java扫描仪的nextShort()方法与示例

發布時間:2023/12/1 java 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nextshort_Java扫描仪的nextShort()方法与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

nextshort

掃描器類的nextShort()方法 (Scanner Class nextShort() method)

Syntax:

句法:

public short nextShort();public short nextShort(int rad);
  • nextShort() method is available in java.util package.

    nextShort()方法在java.util包中可用。

  • nextShort() method is used to read the next token of the input as a short value at the implicit radix of this Scanner.

    nextShort()方法用于讀取輸入的下一個標記,作為此Scanner隱式基數處的短值。

  • nextShort(int rad) method is used to read the next token of the input as a short value at the explicit or given radix(rad) of this Scanner.

    nextShort(int rad)方法用于讀取輸入的下一個標記作為此Scanner的顯式或給定基數(rad)的短值。

  • These methods may throw an exception at the time of representing an input as a short value.

    這些方法在將輸入表示為短值時可能會引發異常。

    • InputMismatchException: This exception may throw when the next token of the input mismatch.InputMismatchException :當輸入的下一個標記不匹配時,可能引發此異常。
    • NoSuchElementException: This exception may throw when no such element exists.NoSuchElementException :如果不存在這樣的元素,則可能引發此異常。
    • IllegalStateException: This exception may throw when this Scanner is not opened.IllegalStateException :如果未打開此掃描器,則可能引發此異常。
  • These are non-static methods and it is accessible with the class object only and if we try to access these methods with the class name then we will get an error.

    這些是非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問這些方法,則會收到錯誤消息。

Parameter(s):

參數:

  • In the first case, nextShort(),

    在第一種情況下, nextShort() ,

    • It does not accept any parameter.
  • In the second case, nextShort(int rad),

    在第二種情況下, nextShort(int rad) ,

    • int rad – represents the radix used to manipulate the token as a short value.
    • int rad –表示用于操縱令牌的基數(短值)。

Return value:

返回值:

In both the cases, the return type of the method is short, it retrieves the short value read from the input.

在這兩種情況下,方法的返回類型均為short ,它檢索從輸入中讀取的short值。

Example 1:

范例1:

// Java program to demonstrate the example // of nextShort() method of Scannerimport java.util.*; import java.util.regex.*;public class NextShort {public static void main(String[] args) {String str = "Java Programming! 3 * 8= 24 + sh";short sh = 1012;// Instantiates ScannerScanner sc = new Scanner(str);while (sc.hasNext()) {// By using nextShort() method isto// return the next token as a // short at the implicit radixif (sc.hasNextShort()) {short next_s = sc.nextShort();System.out.println("sc.nextShort()): " + next_s);}System.out.println(sc.next());}// Scanner closedsc.close();} }

Output

輸出量

Java Programming! sc.nextShort()): 3 * 8= sc.nextShort()): 24 + sh

Example 2:

范例2:

import java.util.*; import java.util.regex.*;public class NextShort {public static void main(String[] args) {String str = "Java Programming! 3 * 8= 24 + sh";short sh = 1012;// Instantiates ScannerScanner sc = new Scanner(str);while (sc.hasNext()) {// By using nextShort(9) method isto// return the next token as a // short at the explicit radixif (sc.hasNextShort()) {short next_s = sc.nextShort(9);System.out.println("sc.nextShort(9)): " + next_s);}System.out.println(sc.next());}// Scanner closedsc.close();} }

Output

輸出量

Java Programming! sc.nextShort(9)): 3 * 8= sc.nextShort(9)): 22 + sh

翻譯自: https://www.includehelp.com/java/scanner-nextshort-method-with-example.aspx

nextshort

總結

以上是生活随笔為你收集整理的nextshort_Java扫描仪的nextShort()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。