java scanner_Java Scanner nextLong()方法與示例

java scanner

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

Syntax:

句法:

    public long nextLong();
public long nextLong(int rad);

  • nextLong() method is available in java.util package.

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

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

    nextLong()方法用于讀取輸入的下一個令牌,作為此Scanner的隱含基數處的長值。

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

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

  • These methods may throw an exception at the time of representing an input as a long 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, nextLong(),

    在第一種情況下, nextLong()

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

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

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

Return value:

返回值:

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

在這兩種情況下,方法的返回類型都是long ,它檢索從輸入讀取的long值。

Example 1:

范例1:

// Java program to demonstrate the example 
// of nextLong() method of Scanner
import java.util.*;
import java.util.regex.*;
public class NextLong {
public static void main(String[] args) {
String str = "Java Programming! 3 * 8= 24 + b";
long l = 101245l;
// Instantiates Scanner
Scanner sc = new Scanner(str);
while (sc.hasNext()) {
// By using nextLong() method isto
// return the next token as a 
// long at the implicit radix
if (sc.hasNextLong()) {
long next_l = sc.nextLong();
System.out.println("sc.nextLong()): " + next_l);
}
System.out.println(sc.next());
}
// Scanner closed
sc.close();
}
}

Output

輸出量

Java
Programming!
sc.nextLong()): 3
*
8=
sc.nextLong()): 24
+
b

Example 2:

范例2:

import java.util.*;
import java.util.regex.*;
public class NextLong {
public static void main(String[] args) {
String str = "Java Programming! 3 * 8= 24 + b";
long l = 101245l;
// Instantiates Scanner
Scanner sc = new Scanner(str);
while (sc.hasNext()) {
// By using nextLong(9) method isto
// return the next token as a 
// long at the explicit radix
if (sc.hasNextLong()) {
long next_l = sc.nextLong(9);
System.out.println("sc.nextLong(9)): " + next_l);
}
System.out.println(sc.next());
}
// Scanner closed
sc.close();
}
}

Output

輸出量

Java
Programming!
sc.nextLong(9)): 3
*
8=
sc.nextLong(9)): 22
+
b

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

java scanner

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378336.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378336.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378336.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

技術總監和CTO的區別 淺談CTO的作用----軟件公司如何開源節流(一)

我一直在思考軟件公司如何開源節流。當然,老板也在思考開源節流。當然,老板思考的開源節流在公司運營層面上,而我作為CTO,我考慮的則是在產品運營角度上來思考這個問題。否則,一個軟件公司,它的生存與發展就…

梯度下降法預測波士頓房價以及簡單的模型評估

目錄原理代碼關于歸一化的思考原理 觀察數據可知屬性之間差距很大,為了平衡所有的屬性對模型參數的影響,首先進行歸一化處理。 每一行是一個記錄,每一列是個屬性,所以對每一列進行歸一化。 二維數組歸一化:1、循環方式…

Windows Phone 內容滑動切換實現

在新聞類的APP中,有一個經常使用的場景:左右滑動屏幕來切換上一條或下一條新聞。 那么通常我們該使用哪種方式去實現呢?可以參考一下Demo的實現步驟。 1,添加Windows Phone用戶自定義控件。例如: 這里我為了演示的方便…

c語言interrupt函數,中斷處理函數數組interrupt[]初始化

在系統初始化期間,trap_init()函數將對中斷描述符表IDT進行第二次初始化(第一次只是建一張IDT表,讓其指向ignore_intr函數),而在這次初始化期間,系統的0~19號中斷(用于分NMI和異常的中斷向量)均被設置好。與此同時,用于…

bytevalue_Java Number byteValue()方法與示例

bytevalueNumber類byteValue()方法 (Number Class byteValue() method) byteValue() method is available in java.lang package. byteValue()方法在java.lang包中可用。 byteValue() method is used to return the value denoted by this Number object converted to type byt…

第二章 染色熱力學理論單元測驗

1,()測定是染色熱力學性能研究的基礎 吸附等溫線。 2,吸附是放熱反應,溫度升高,親和力() 減小 3,染色系統中包括() 染料。 染深色介質。 染色助劑。 纖維。 4,下列對狀態函數特點敘述正確的為() 狀態函數只有在平衡狀態的系統中才有確定值。 在非平衡狀態的系統…

使用鳶尾花數據集實現一元邏輯回歸、多分類問題

目錄鳶尾花數據集邏輯回歸原理【1】從線性回歸到廣義線性回歸【2】邏輯回歸【3】損失函數【4】總結TensorFlow實現一元邏輯回歸多分類問題原理獨熱編碼多分類的模型參數損失函數CCETensorFlow實現多分類問題獨熱編碼計算準確率計算交叉熵損失函數使用花瓣長度、花瓣寬度將三種鳶…

開源HTML5應用開發框架 - iio Engine

隨著HTML5的發展,越來越多的基于HTML5技術的網頁開發框架出現,在今天的這篇文章中,我們將介紹iio Engine,它是一款開源的創建HTML5應用的web框架。整個框架非常的輕量級,只有45kb大小,并且整合了debug系統&…

c語言double root,C語言修仙

root(1)(2/2)AD1AD4林潯合理推測,青城山劍宗,也就是祁云所在的劍修一脈,掌握著一些道修并不知道的傳承。譬如——怎樣找到赤霄龍雀劍,又或者,怎樣使用它。這樣一來,青城的守衛陣法沒有反應也能解釋了&#…

【轉】Black Box

Introduction BlackBox是FPGA設計中一個重要的技巧,不過覺得Xilinx的文檔沒有很好地將它講清楚。 BlackBox的主要想法就是把設計的某一個子模塊單獨綜合,綜合的結果作為一個黑盒子子模塊,上層設計不再對這個模塊進行優化,只能看到…

Java Compiler disable()方法與示例

編譯器類disable()方法 (Compiler Class disable() method) disable() method is available in java.lang package. disable()方法在java.lang包中可用。 disable() method is used to cause the compiler to stop operation. disable()方法用于使編譯器停止操作。 disable() m…

【神經網絡計算】——神經網絡實現鳶尾花分類

本blog為觀看MOOC視頻與網易云課堂所做的筆記 課堂鏈接: 人工智能實踐:TensorFlow筆記 吳恩達機器學習 疑問與思考 為什么按照batch喂入數據 之前看的視頻里面處理數據都是一次性將所有數據喂入,現在看的這個視頻對數據進行了分組投入。這是為何&#…

第三章 染色動力學理論單元測試

1,準二級動力學模型認為,染色速率與()的二次方成正比 纖維上未被占滿的位置(空位)數量 2,研究染色動力學的意義有() 了解染料走向平衡的速率。 初染速率。 勻染性。 3,求出染料的擴散系數的意義有() 了解各因素對擴散系數的影響。 求出不同溫度下的擴散系數,計算…

CDOJ--1668

原題鏈接:http://acm.uestc.edu.cn/problem.php?pid1668 由于題目意思指的是將分數拆分成不同的單位分數之和,所以就不用考慮將2/3拆成1/31/3這種情況了;又由于好的拆分要求項數即len要少,最小的項要大,故可以采用迭代…

c# xaml語言教程,c#學習之30分鐘學會XAML

1.狂妄的WPF相對傳統的Windows圖形編程,需要做很多復雜的工作,引用許多不同的API。例如:WinForm(帶控件表單)、GDI(2D圖形)、DirectXAPI(3D圖形)以及流媒體和流文檔等,都需要不同的API來構建應用程序。WPF就是看著上面的操作復雜和…

(Android實戰)AsyncTask和Handler兩種異步方式實現原理和優缺點比較

1 AsyncTask實現的原理,和適用的優缺點 AsyncTask,是android提供的輕量級的異步類,可以直接繼承AsyncTask,在類中實現異步操作,并提供接口反饋當前異步執行的程度(可以通過接口實現UI進度更新),最后反饋執行的結果給UI主線程. 使用的優點: l 簡單,快捷 l 過程可控 使用的缺點…

Java Collections list()方法與示例

集合類list()方法 (Collections Class list() method) list() method is available in java.util package. list()方法在java.util包中可用。 list() method is used to return an array list that contains all the elements returned by the given Enumeration and the way o…

第八章 異常

第八章 異常 異常事件可能是錯誤(如試圖除以零),也可能是通常不會發生的事情。 Python提供功能強大的替代解決方案——異常處理機制。 異常是什么? Python使用異常對象來表示異常狀態,并在遇到錯誤時引發異常。異常…

hdu 1564 Play a game

對于本題,若要當前的 player 贏,剩下所走的步數必須是奇數步。所以對于每步的 player 所放棄的選擇的步數為偶數步。因此,對于整個 game 來說,所放棄的步數 m 為偶數步,設所走的步數為 k ,則 n*n-1mk&…

【電設控制與圖像訓練題】【激光打靶】【opencv測試代碼以及效果】

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 規則 激光槍自動射擊裝置(E題) 【本科組】 一、任務 設計一個能夠控制激光槍擊發、自動報靶及自動瞄準等功能的電子系統。該…