nextboolean()_Java Random nextBoolean()方法与示例
nextboolean()
隨機類nextBoolean()方法 (Random Class nextBoolean() method)
nextBoolean() method is available in java.util package.
nextBoolean()方法在java.util包中可用。
nextBoolean() method is used to return the next pseudo-random Boolean value from this Random Value Generator.
nextBoolean()方法用于從此“隨機值生成器”返回下一個偽隨機布爾值。
nextBoolean() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
nextBoolean()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
nextBoolean() method does not throw an exception at the time of returning boolean.
nextBoolean()方法在返回布爾值時不會引發異常。
Syntax:
句法:
public boolean nextBoolean();Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of the method is boolean, it returns the next pseudo-random distributed boolean value.
該方法的返回類型為boolean ,它返回下一個偽隨機分布的布爾值。
Example:
例:
// Java program to demonstrate the example // of boolean nextBoolean() method of // Randomimport java.util.*;public class NextBooleanOfRandom {public static void main(String args[]) {// Instantiates Random objectRandom ran = new Random();// By using nextBoolean() method is// to return the next to next// pseudo-random boolean value from// this Random Value Generatorboolean val = ran.nextBoolean();// Display valSystem.out.println("ran.nextBoolean(): " + val);} }Output
輸出量
RUN 1: ran.nextBoolean(): falseRUN 2: ran.nextBoolean(): trueRUN 3: ran.nextBoolean(): false翻譯自: https://www.includehelp.com/java/random-nextboolean-method-with-example.aspx
nextboolean()
總結
以上是生活随笔為你收集整理的nextboolean()_Java Random nextBoolean()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java vector_Java Vec
- 下一篇: ai建立使用图案_ai自定义图案的方法详