object
a data type that is created in Java
Math class
stores common numbers used in mathematical calculations and methods that have mathematical functions
static method
belong to a class but not to any instances of that specific class
can be called without class’s instance or object
Math.abs(x)
gets the absolute value of ‘x’ ; the return value is always positive
Math.pow(x,y)
does ‘x’ to the power of ‘y’ (x^y); the answer will always be a double(decimal) value
Math.PI
stores the value for pi: 3.141592653…
charAt(int x)
returns the char at the given index of ‘x’
contains(String s)
returns true when received string is within the called string, false otherwise
endsWith(String s)
returns true when received string ends with called string, false otherwise
equals(String s)
returns true when the two strings are equal, false otherwise
equalsIgnoreCase(String s)
returns true when the two strings are equal ignoring the case( lower or upper), false otherwise
public class Example{
public static void main(String[] args){
String s = "I like apples";
String g = "ILIKEAPPLES";
//What is returned from this line of code?
System.out.println(s.equals(g));
}
}
false
public class Example{
public static void main(String[] args){
String s = "I like apples";
String g = "ILIKEAPPLES";
//What is returned from this line of code?
System.out.println(toLowerCase(g));
}
}
ilikeapples
public class Example{
public static void main(String[] args){
int x = 2;
int y = 10;
int z = Math.pow(y,x);
System.out.println(z);
}
}
100.00
public class Example{
public static void main(String[] args){
int x = 2;
int y = -10.9;
int z = Math.abs(y);
//what is printed from this program
System.out.println(z);
}
}
10.9
public class Example{
public static void main(String[] args){
String hi = "hello, John Harvard";
//what is printed from this program?
System.out.println(hi.charAT(7));
}
}
J