Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Java Class Library

Similar presentations


Presentation on theme: "Using Java Class Library"— Presentation transcript:

1 Using Java Class Library
Some other useful classes to use

2 Import declaration Each class in the library must be imported
You can use the * as a wild card with import statements import statements go before the class heading

3 Scanner Class Constructors String next() String nextLine()
Scanner(InputStream source) Scanner(File source) Scanner(String source) String next() Returns the next input token as a character string String nextLine() returns all input remaining on the current line as a character string

4 Scanner class boolean nextBoolean() byte nextByte()
double nextDouble() float nextFloat() int nextInt() long nextLong() short nextShort() returns the next input token as the indicated type. Throws InputMismatchException if the next token is inconsistent with the type

5 Random class Random() double nextDouble() int nextInt(int num)
constructor: creates a new pseudorandom number generator double nextDouble() returns a random number between 0.0 inclusive and 1.0 exclusive int nextInt(int num) Returns a random number in the range of 1 to num-1

6 Math class Don’t import anything static int abs(int num)
static double abs(double num) returns the absolute value of num static double pow(double num, double power) returns the value num raised to the specified power static double sqrt(double num) returns the square root of num, which must be positive

7 DecimalFormat class DecimalFormat(String pattern)
Constructor: creates a new DecimalFormat object with the specified pattern void applyPattern(String pattern) applies the specified pattern to this DecimalFormat object String format(double number) returns a string containing the specified number formatted according to the current pattern.

8 String class Can use the = operator and “ “ to construct string
other useful methods char charAt(int index) boolean equals(String str) boolean equalsIgnoreCase(String str) int indexOf(String str) int length() String toLowerCase() String toUpperCase()


Download ppt "Using Java Class Library"

Similar presentations


Ads by Google