Annexes: Aide en Ligne Sur Random
Annexes: Aide en Ligne Sur Random
protected next(int bits) Generates the next pseudorandom number. int boolean
nextBoolean() Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence. nextBytes(byte[] bytes) Generates random bytes and places them into a user-supplied byte array. nextDouble() Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence. nextFloat() Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence. nextGaussian() Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence. nextInt() Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence. nextInt(int n) Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. nextLong() Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.
void double
float
double
int
int
long
48/56
void
setSeed(long seed) Sets the seed of this random number generator using a single long seed.
Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Terminates this timer, discarding any currently scheduled tasks. Removes all cancelled tasks from this timer's task queue. Schedules the specified task for execution at the specified time.
Schedules the specified task for repeated fixed-delay execution, beginning at the specified time. Schedules the specified task for execution after the specified delay.
49/56
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. Schedules the specified task for repeated fixed-rate execution, beginning at the specified time. Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
protected TimerTask()
Method Summary
boolean
cancel() Cancels this timer task. The action to be performed by this timer task.
scheduledExecutionTime() Returns the scheduled execution time of the most recent actual execution of this task.
Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
50/56
} The scanner can also use delimiters other than whitespace. This example reads several items in from a string: String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*"); System.out.println(s.nextInt()); System.out.println(s.nextInt()); System.out.println(s.next()); System.out.println(s.next()); s.close(); prints the following output: 1 2 red blue The same output can be generated with this code, which uses a regular expression to parse all four tokens at once: String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input); s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); MatchResult result = s.match(); for (int i=1; i<=result.groupCount(); i++) System.out.println(result.group(i)); s.close(); The default whitespace delimiter used by a scanner is as recognized by Character.isWhitespace. The reset() method will reset the value of the scanner's delimiter to the default whitespace delimiter regardless of whether it was previously changed. A scanning operation may block waiting for input. The next() and hasNext() methods and their primitive-type companion methods (such as nextInt() and hasNextInt()) first skip any input that matches the delimiter pattern, and then attempt to return the next token. Both hasNext and next methods may block waiting for further input. Whether a hasNext method blocks has no connection to whether or not its associated next method will block. The findInLine(java.lang.String), findWithinHorizon(java.lang.String, int), and skip(java.util.regex.Pattern) methods operate independently of the delimiter pattern. These methods will attempt to match the specified pattern with no regard to delimiters in the input and thus can be used in special circumstances where delimiters are not relevant. These methods may block waiting for more input. When a scanner throws an InputMismatchException, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method. Depending upon the type of delimiting pattern, empty tokens may be returned. For example, the pattern "\\s+" will return no empty tokens since it matches multiple instances of the delimiter. The delimiting pattern "\\s" could return empty tokens since it only passes one space at a time. A scanner can read text from any object which implements the Readable interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer) method throws an IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException() method. When a Scanner is closed, it will close its input source if the source implements the Closeable interface. A Scanner is not safe for multithreaded use without external synchronization. Unless otherwise mentioned, passing a null parameter into any method of a Scanner will cause a NullPointerException to be thrown. A scanner will default to interpreting numbers as decimal unless a different radix has been set by using the useRadix(int) method. The reset() method will reset the value of the scanner's radix to 10 regardless of whether it was previously changed. Localized numbers An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the Locale.getDefault() method; it may be changed via the useLocale(java.util.Locale) method. The reset() method will reset the value of the scanner's locale to the initial locale regardless of whether it was previously changed. Constructor Summary Scanner(File source) Constructs a new Scanner that produces values scanned from the specified file. Scanner(File source, String charsetName) Constructs a new Scanner that produces values scanned from the specified file. Scanner(InputStream source) Constructs a new Scanner that produces values scanned from the specified input stream. Scanner(InputStream source, String charsetName) Constructs a new Scanner that produces values scanned from the specified input
51/56
stream. Scanner(Readable source) Constructs a new Scanner that produces values scanned from the specified source. Scanner(ReadableByteChannel source) Constructs a new Scanner that produces values scanned from the specified channel. Scanner(ReadableByteChannel source, String charsetName) Constructs a new Scanner that produces values scanned from the specified channel. Scanner(String source) Constructs a new Scanner that produces values scanned from the specified string. Method Summary
void Pattern
close() Closes this scanner. delimiter() Returns the Pattern this Scanner is currently using to match delimiters. findInLine(Pattern pattern) Attempts to find the next occurrence of the specified pattern ignoring delimiters. findInLine(String pattern) Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters. findWithinHorizon(Pattern pattern, int horizon) Attempts to find the next occurrence of the specified pattern. findWithinHorizon(String pattern, int horizon) Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters. hasNext() Returns true if this scanner has another token in its input. hasNext(Pattern pattern) Returns true if the next complete token matches the specified pattern. hasNext(String pattern) Returns true if the next token matches the pattern constructed from the specified string. hasNextBigDecimal() Returns true if the next token in this scanner's input can be interpreted as a BigDecimal using the nextBigDecimal() method. hasNextBigInteger() Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the default radix using the nextBigInteger() method. hasNextBigInteger(int radix) Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the specified radix using the nextBigInteger() method. hasNextBoolean() Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false". hasNextByte() Returns true if the next token in this scanner's input can be interpreted as a byte value in the default radix using the nextByte() method. hasNextByte(int radix) Returns true if the next token in this scanner's input can be interpreted as a byte value in the specified radix using the nextByte() method. hasNextDouble() Returns true if the next token in this scanner's input can be interpreted as a double value using the nextDouble() method. hasNextFloat() Returns true if the next token in this scanner's input can be interpreted as a float value using the nextFloat() method.
String
String
String String
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
52/56
boolean
hasNextInt() Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the nextInt() method. hasNextInt(int radix) Returns true if the next token in this scanner's input can be interpreted as an int value in the specified radix using the nextInt() method. hasNextLine() Returns true if there is another line in the input of this scanner. hasNextLong() Returns true if the next token in this scanner's input can be interpreted as a long value in the default radix using the nextLong() method. hasNextLong(int radix) Returns true if the next token in this scanner's input can be interpreted as a long value in the specified radix using the nextLong() method. hasNextShort() Returns true if the next token in this scanner's input can be interpreted as a short value in the default radix using the nextShort() method. hasNextShort(int radix) Returns true if the next token in this scanner's input can be interpreted as a short value in the specified radix using the nextShort() method. ioException() Returns the IOException last thrown by this Scanner's underlying Readable. locale() Returns this scanner's locale. match() Returns the match result of the last scanning operation performed by this scanner. next() Finds and returns the next complete token from this scanner. next(Pattern pattern) Returns the next token if it matches the specified pattern. next(String pattern) Returns the next token if it matches the pattern constructed from the specified string. nextBigDecimal() Scans the next token of the input as a BigDecimal. nextBigInteger() Scans the next token of the input as a BigInteger. nextBigInteger(int radix) Scans the next token of the input as a BigInteger. nextBoolean() Scans the next token of the input into a boolean value and returns that value. nextByte() Scans the next token of the input as a byte. nextByte(int radix) Scans the next token of the input as a byte. nextDouble() Scans the next token of the input as a double. nextFloat() Scans the next token of the input as a float. nextInt() Scans the next token of the input as an int. nextInt(int radix) Scans the next token of the input as an int. nextLine() Advances this scanner past the current line and returns the input that was skipped.
boolean
boolean boolean
boolean
boolean
boolean
IOException
Locale MatchResult
53/56
nextLong() Scans the next token of the input as a long. nextLong(int radix) Scans the next token of the input as a long. nextShort() Scans the next token of the input as a short. nextShort(int radix) Scans the next token of the input as a short. radix() Returns this scanner's default radix. remove() The remove operation is not supported by this implementation of Iterator. reset() Resets this scanner. skip(Pattern pattern) Skips input that matches the specified pattern, ignoring delimiters. skip(String pattern) Skips input that matches a pattern constructed from the specified string. toString() Returns the string representation of this Scanner. useDelimiter(Pattern pattern) Sets this scanner's delimiting pattern to the specified pattern. useDelimiter(String pattern) Sets this scanner's delimiting pattern to a pattern constructed from the specified String. useLocale(Locale locale) Sets this scanner's locale to the specified locale. useRadix(int radix) Sets this scanner's default radix to the specified radix.
Scanner Scanner
Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
err The "standard" error output stream. in The "standard" input stream. out The "standard" output stream.
Method Summary
static void
arraycopy(Object src, int srcPos, Object dest, int destPos, int length) Copies an array from the specified source array, beginning
54/56
clearProperty(String key) Removes the system property indicated by the specified key. console() Returns the unique Console object associated with the current Java virtual machine, if any. currentTimeMillis() Returns the current time in milliseconds. exit(int status) Terminates the currently running Java Virtual Machine. gc() Runs the garbage collector. Returns an unmodifiable string map view of the current system environment. getenv(String name) Gets the value of the specified environment variable. getProperties() Determines the current system properties. getProperty(String key) Gets the system property indicated by the specified key. getProperty(String key, String def) Gets the system property indicated by the specified key. getSecurityManager() Gets the system security interface. identityHashCode(Object x) Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode(). inheritedChannel() Returns the channel inherited from the entity that created this Java virtual machine. load(String filename) Loads a code file with the specified filename from the local file system as a dynamic library. loadLibrary(String libname) Loads the system library specified by the libname argument. mapLibraryName(String libname) Maps a library name into a platform-specific string representing a native library. nanoTime() Returns the current value of the most precise available system timer, in nanoseconds. runFinalization() Runs the finalization methods of any objects pending finalization. runFinalizersOnExit(boolean value) Deprecated. This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock. setErr(PrintStream err) Reassigns the "standard" error output stream. setIn(InputStream in) Reassigns the "standard" input stream. setOut(PrintStream out) Reassigns the "standard" output stream. setProperties(Properties props) Sets the system properties to the Properties argument.
static Map<String,Strin getenv() g> static String static Properties static String static String static SecurityManager static int
static Channel
static void
static long
static void
static void
55/56
static String
setProperty(String key, String value) Sets the system property indicated by the specified key.
Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
56/56