java 方法 示例_Java掃描儀具有示例的NextNextInt()方法

java 方法 示例

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

Syntax:

句法:

    public boolean hasNextInt();
public boolean hasNextInt(int rad);

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

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

  • hasNextInt() method is used to check whether this Scanner has next token in its input can be manipulated as an int in the implicit radix (rad) or not.

    hasNextInt()方法用于檢查此掃描程序在其輸入中是否具有下一個標記是否可以作為隱式基數(rad)中的int進行操作。

  • hasNextInt(int rad) method is used to check whether this Scanner has next token in its input can be manipulated as an int in the explicit or given radix (rad) or not.

    hasNextInt(int rad)方法用于檢查此掃描程序在其輸入中是否具有下一個標記,可以將其作為顯式或給定基數(rad)中的int進行操作。

  • These methods may throw an exception at the time of representing input as an int.

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

    IllegalStateException: This exception may throw when this Scanner is not opened.

    IllegalStateException :如果未打開此掃描器,則可能引發此異常。

  • These are non-static methods, it is accessible with class object & if we try to access these methods with the class name then we will get an error.

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

Parameter(s):

參數:

  • In the first case, hasNextInt(),

    在第一種情況下, hasNextInt()

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

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

    • int rad – represents the radix used to manipulate as an int.
    • int rad –表示用作int的基數。

Return value:

返回值:

In both the cases, the return type of the method is boolean, it returns true when this Scanner next input as an int otherwise it returns false.

在這兩種情況下,方法的返回類型是布爾值 ,當這種掃描儀下一個輸入為一個int否則返回false返回true。

Example:

例:

// Java program is to demonstrate the example
// of hasNextInt() method of Scanner
import java.util.*;
import java.util.regex.*;
public class HasNextInt {
public static void main(String[] args) {
String str = "Java Programming! 3 * 8= 24";
// Instantiates Scanner
Scanner sc = new Scanner(str);
while (sc.hasNext()) {
// By using hasNextInt() method is to
// check whether this object next token
// represents int or not in the default 
// radix
boolean status = sc.hasNextInt();
System.out.println("sc.hasNextInt(): " + status);
// By using hasNextInt(radix) method is to
// check whether this object next token
// represents integer in the given radix
// or not
status = sc.hasNextInt(2);
System.out.println("sc.hasNextInt(2): " + status);
sc.next();
}
// Scanner closed
sc.close();
}
}

Output

輸出量

sc.hasNextInt(): false
sc.hasNextInt(2): false
sc.hasNextInt(): false
sc.hasNextInt(2): false
sc.hasNextInt(): true
sc.hasNextInt(2): false
sc.hasNextInt(): false
sc.hasNextInt(2): false
sc.hasNextInt(): false
sc.hasNextInt(2): false
sc.hasNextInt(): true
sc.hasNextInt(2): false

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

java 方法 示例

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

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

相關文章

axis2開發webservice之編寫Axis2模塊(Module)

axis2中的模塊化開發。能夠讓開發者自由的加入自己所需的模塊。提高開發效率,減少開發的難度。 Axis2能夠通過模塊(Module)進行擴展。Axis2模塊至少須要有兩個類,這兩個類分別實現了Module和Handler接口。開發和使用一個Axis2模塊…

java 看書瀏覽器官_JAVA讀取文件流,設置瀏覽器下載或直接預覽操作

最近項目需要在瀏覽器中通過url預覽圖片。但發現瀏覽器始終默認下載,而不是預覽。研究了一下,發現了問題:// 設置response的header,注意這句,如果開啟,默認瀏覽器會進行下載操作,如果注釋掉&…

Java PriorityQueue poll()方法與示例

PriorityQueue類poll()方法 (PriorityQueue Class poll() method) poll() method is available in java.util package. poll()方法在java.util包中可用。 poll() method is used to return the first element with removing an element from this PriorityQueue. poll()方法用于…

scrapy抓取淘寶女郎

scrapy抓取淘寶女郎 準備工作 首先在淘寶女郎的首頁這里查看,當然想要爬取更多的話,當然這里要查看翻頁的url,不過這操蛋的地方就是這里的翻頁是使用javascript加載的,這個就有點尷尬了,找了好久沒有找到,這里如果有朋…

map在Java集合_java集合之Map

MapMap用于保存具有映射關系的數據。Map中key不允許重復,value可以重復,key和value之間存在單向一對一關系HashMap和Hashtable區別1 Hashtable線程安全、HashMap線程不安全,所以HashMap性能高一點2 Hashtable不允許用null做key和value&#x…

Java OutputStream close()方法與示例

OutputStream類close()方法 (OutputStream Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this OutputStream stream and free all system resources linked with this stream and …

怎樣在fastboot 里面加入新的命令

fastboot 是android 默認的一種debug 方法。它的優點是在進入linux kernel 之前就可以操作。默認fastboot 支持的命令&#xff1a; usage: fastboot [ <option> ] <command>commands: update <filename> reflash device …

java編寫字符串連接程序注釋_Java 注解自動化處理對應關系實現注釋代碼化

public class EsQuery { private static int DEFAULT_SIZE 100; private final Map termFilter;private final Map rangeFilter;private final Map matchFilter;private int size;private String orderBy null;private String order null; // query 查詢語法, 是否需要 filtere…

getlanguage_Java語言環境getLanguage()方法與示例

getlanguage區域設置類getLanguage()方法 (Locale Class getLanguage() method) getLanguage() method is available in java.util package. getLanguage()方法在java.util包中可用。 getLanguage() method is used to retrieve this Locale language code and the language co…

[轉]Anaconda

安裝 Anaconda Anaconda 可用于 Windows、Mac OS X 和 Linux。可以在 https://www.continuum.io/down... 上找到安裝程序和安裝說明。 如果計算機上已經安裝了 Python&#xff0c;這不會有任何影響。實際上&#xff0c;腳本和程序使用的默認 Python 是 Anaconda 附帶的 Python。…

win10 iot core java_Windows 10 IoT Core 正式版初體驗

今天收到Windows 10 IoT Core Team郵件&#xff0c;Windows 10 IoT Core正式發布。以下記錄了今天在Raspberry Pi 2上的體驗過程&#xff1a;準備工作一臺運行著正版Windows 10且版本不小于10240的個人PCVisual Studio 2015 版本不小于14.0.23107.0 D14Rel Install Visual Stud…

filterwriter_Java FilterWriter flush()方法與示例

filterwriterFilterWriter類flush()方法 (FilterWriter Class flush() method) flush() method is available in java.io package. flush()方法在java.io包中可用。 flush() method is used to flush out the string from this FilterWriter stream. flush()方法用于從此Filter…

VUE2 第五天學習--過渡效果

閱讀目錄 1.理解VUE---過渡效果回到頂部1.理解VUE---過渡效果 1. 過渡的-css-類名會有4個(css) 類名在 enter/leave 在過渡中切換。1. v-enter: 進入過渡的開始狀態。在元素被插入時生效&#xff0c;在下一個幀移除。2. v-enter-active: 進入過渡的結束狀態。在元素被插入時生效…

java 集合addall_Java集合的addAll()方法和示例

java 集合addall集合類的addAll()方法 (Collections Class addAll() method) addAll() Method is available in java.lang package. addAll()方法在java.lang包中可用。 addAll() Method is used to put all the given elements(ele) to the given collection (co). addAll()方…

國家可持續發展議程創新示范區創建工作推進會在北京召開

2019獨角獸企業重金招聘Python工程師標準>>> 為推進地方申報國家可持續發展議程創新示范區相關工作&#xff0c;根據國家可持續發展議程創新示范區創建工作的進展及需求&#xff0c;2017年4月23日—25日&#xff0c;科技部社會發展科技司、中國21世紀議程管理中心在…

java控制臺打印圖片_java——控制臺輸入打印圖形

1. 打印直角三角形需求說明&#xff1a;從控制臺輸入直角三角形的高度(行數)。每行*的數目依次為1、3、5、7等。實現思路&#xff1a;外層循環控制行數&#xff0c;根據用戶輸入的行數得到外層循環條件分析每行打印的內容&#xff1a;每一行均打印*號&#xff0c;第i行的*號數為…

Java日歷compareTo()方法與示例

日歷類的compareTo()方法 (Calendar Class compareTo() method) compareTo() method is available in java.util package. compareTo()方法在java.util包中可用。 compareTo() method is used to compare two Calendar objects or in other words, we can say this method is u…

在struts2中配置自定義攔截器放行多個方法

源碼&#xff1a; 自定義的攔截器類&#xff1a; //自定義攔截器類:LoginInterceptor ; package com.java.action.interceptor; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionInvocation;im…

java多態和泛型_Java面向對象(二) 接口、多態和泛型

一、接口二、多態多態是同一個行為具有多個不同表現形式或形態的能力。2.1 類型轉換轉換方式隱式 向上轉型對于基本數據類型&#xff0c;存儲容量低的可自動向存儲容量高的類型轉換對于引用變量&#xff0c;子類可被轉換為超類&#xff0c;可被賦給所屬類實現的接口的引用顯式 …

Java ArrayList contains()方法及示例

ArrayList類contains()方法 (ArrayList Class contains() method) contains() method is available in java.util package. contains()方法在java.util包中可用。 contains() method is used to check whether this Arraylist contains the given object or not. contains()方法…