double x = 4;
double root = x.sqrt(); // Error
double root = Math.sqrt(x);
Math System.out
How do you compute xy in Java?
pow
instance method that has one explicit
parameter: x.pow(y)
pow
instance method that has two explicit
parameters: Math.pow(x, y)
pow
static method that has one explicit parameter:
x.pow(y)
pow
static method that has two explicit parameters:
Math.pow(x, y)
What best describes the call System.out.println(4)?
println
is a static method of the class
System.out
out.println
is a static method of the class
System
println
is an instance method with implicit parameter
System.out
println
is an instance method with implicit parameter
4
"Hello, World!"
String name = "Dave"; String message = "Hello, " + name; // message is "Hello, Dave"
String a = "Agent"; int n = 7; String bond = a + n; // bond is "Agent7"
System.out.print("The total is "); System.out.println(total);
versus
System.out.println("The total is " + total);
int n = Integer.parseInt(str); double x = Double.parseDouble(x);
String str = "" + n; str = Integer.toString(n);
String greeting = "Hello, World!"; String sub = greeting.substring(0, 5); // sub is "Hello"
past the endposition
past the end- start
What does the following code segment print?
String s = "Agent"; s = s + "00" + s.length(); s = s.substring(0, 5) + s.substring(6, s.length() - 1); System.out.println(s);
Scanner in = new Scanner(System.in); System.out.print("Enter quantity:"); int quantity = in.nextInt();
Suppose in is a Scanner object that reads from System.in, and your program calls
String name = in.next(); int n = in.nextInt();
What is the value of name and n
if the user enters
Agent 0.07
?
name
is Agent 007
, n
is 0name
is Agent
, n
is
0
name
is Agent
, n
is
0.07