Basic Built-in Methods
All the methods that are being printed can also have their result set to a variable.
Anatomy of a Method
name(arg1, arg2 ...)
name
is where a method name would go()
is where we can place our require arguments for the methodarg1
is a placeholder for a possible argument
Example: System.out.println("Hello, World!")
System.out.println("Hello, World!")
System.out.println
is the name of our method"Hello, World!"
is our argument provided to our method
Math Methods
Math.round()
converts your double to the nearest integer value.
Math.ceil()
stands for "ceiling" and rounds a number up to the nearest integer.For example,
Math.ceil(4.3)
would return5.0
.
Math.floor()
stands for "floor" and rounds a number down to the nearest integer. For example,Math.floor(4.8)
would return4.0
.These functions are often used when you need to work with whole numbers or want to adjust a decimal number to the nearest integer in a specific direction
Math.min()
will provide the smaller value between the two arguments provided
Math.max()
will provide the larger value between the two arguments provided
Math.sqrt
will return a square root of the given numeric argument
Math.random()
requires no arguments; it generates a random number from 0 to 1 (not including)For my execution of the code it generated 0.1243868832888797
Basic String Methods
Since
text
is a string type variable, we can access its methods (its super powers) by inserting a period.
after the variable name.
.length()
will provide the number of characters that made up the strings
.toUpperCase()
converts the string to all uppercase
.toLowerCase()
converts the string to all lowercase
Last updated