0% found this document useful (0 votes)
81 views9 pages

Annexes: Aide en Ligne Sur Random

The document provides documentation on the Java Scanner class. It summarizes that Scanner is used to parse primitive types and strings from text input using regular expressions. It breaks input into tokens using a delimiter pattern (by default whitespace) and provides methods like nextInt() and nextDouble() to retrieve the next token as a specific type. Scanner can use custom delimiters and handles blocking to wait for input as needed.

Uploaded by

Yoann Clombe
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views9 pages

Annexes: Aide en Ligne Sur Random

The document provides documentation on the Java Scanner class. It summarizes that Scanner is used to parse primitive types and strings from text input using regular expressions. It breaks input into tokens using a delimiter pattern (by default whitespace) and provides methods like nextInt() and nextDouble() to retrieve the next token as a specific type. Scanner can use custom delimiters and handles blocking to wait for input as needed.

Uploaded by

Yoann Clombe
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Annexes

Aide en ligne sur Random


java.util
Class Random java.lang.Object java.util.Random All Implemented Interfaces: Serializable Direct Known Subclasses: SecureRandom public class Randomextends Objectimplements Serializable An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 3, Section 3.2.1.) If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. In order to guarantee this property, particular algorithms are specified for the class Random. Java implementations must use all the algorithms shown here for the class Random, for the sake of absolute portability of Java code. However, subclasses of class Random are permitted to use other algorithms, so long as they adhere to the general contracts for all the methods. The algorithms implemented by class Random use a protected utility method that on each invocation can supply up to 32 pseudorandomly generated bits. Many applications will find the method Math.random() simpler to use. Since: 1.0 See Also: Serialized Form Constructor Summary Random() Creates a new random number generator. Random(long seed) Creates a new random number generator using a single long seed. Method Summary

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

Aide en ligne sur Timer


java.util
Class Timer java.lang.Object java.util.Timer public class Timerextends Object A facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes. After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer's task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur. By default, the task execution thread does not run as a daemon thread, so it is capable of keeping an application from terminating. If a caller wants to terminate a timer's task execution thread rapidly, the caller should invoke the timer's cancel method. If the timer's task execution thread terminates unexpectedly, for example, because its stop method is invoked, any further attempt to schedule a task on the timer will result in an IllegalStateException, as if the timer's cancel method had been invoked. This class is thread-safe: multiple threads can share a single Timer object without the need for external synchronization. This class does not offer real-time guarantees: it schedules tasks using the Object.wait(long) method. Implementation note: This class scales to large numbers of concurrently scheduled tasks (thousands should present no problem). Internally, it uses a binary heap to represent its task queue, so the cost to schedule a task is O(log n), where n is the number of concurrently scheduled tasks. Implementation note: All constructors start a timer thread. Since: 1.3 See Also: TimerTask, Object.wait(long) Constructor Summary Timer() Creates a new timer. Timer(boolean isDaemon) Creates a new timer whose associated thread may be specified to run as a daemon. Timer(String name) Creates a new timer whose associated thread has the specified name. Timer(String name, boolean isDaemon) Creates a new timer whose associated thread has the specified name, and may be specified to run as a daemon. Method Summary

void cancel() int


purge()

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.

void schedule(TimerTask task, Date time)

void schedule(TimerTask task, Date firstTime, long period)

Schedules the specified task for repeated fixed-delay execution, beginning at the specified time. Schedules the specified task for execution after the specified delay.

void schedule(TimerTask task, long delay)

49/56

void schedule(TimerTask task, long delay, long period)

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.

void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)

void scheduleAtFixedRate(TimerTask task, long delay, long period)

Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Aide en ligne sur TimerTask


java.util
Class TimerTask java.lang.Object java.util.TimerTask All Implemented Interfaces: Runnable public abstract class TimerTaskextends Objectimplements Runnable A task that can be scheduled for one-time or repeated execution by a Timer. Since: 1.3 See Also: Timer Constructor Summary

protected TimerTask()

Creates a new timer task.

Method Summary

boolean

cancel() Cancels this timer task. The action to be performed by this timer task.

abstract run() void long

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

Aide en ligne sur Scanner


Class Scanner java.lang.Object java.util.Scanner All Implemented Interfaces: Iterator<String> public final class Scannerextends Objectimplements Iterator<String> A simple text scanner which can parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods. For example, this code allows a user to read a number from System.in: Scanner sc = new Scanner(System.in); int i = sc.nextInt(); As another example, this code allows long types to be assigned from entries in a file myNumbers: Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasNextLong()) { long aLong = sc.nextLong();

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

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

String String String

BigDecimal BigInteger BigInteger boolean

byte byte double float int int String

53/56

long long short short int void

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 Scanner

String Scanner Scanner

Scanner Scanner

Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Aide en ligne sur System


java.lang
Class System java.lang.Object java.lang.System public final class Systemextends Object The System class contains several useful class fields and methods. It cannot be instantiated. Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array. Since: JDK1.0 Field Summary

static PrintStream static InputStream static PrintStream

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

at the specified position, to the specified position of the destination array.

static String static Console

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 long static void static void

static Map<String,Strin getenv() g> static String static Properties static String static String static SecurityManager static int

static Channel

static void

static void static String

static long

static void

static void

static void static void 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

You might also like