CS 46A - Lecture 10

Cover page image

Pre-class reading

Calling Static Methods

Syntax 4.3 Static Method Call

Syntax 4.3 Static Method Call

Lecture 10 Clicker Question 1

How do you compute xy in Java?

  1. With the pow instance method that has one explicit parameter: x.pow(y)
  2. With the pow instance method that has two explicit parameters: Math.pow(x, y)
  3. With the pow static method that has one explicit parameter: x.pow(y)
  4. With the pow static method that has two explicit parameters: Math.pow(x, y)

Lecture 10 Clicker Question 2

What best describes the call System.out.println(4)?

  1. println is a static method of the class System.out
  2. out.println is a static method of the class System
  3. println is an instance method with implicit parameter System.out
  4. println is an instance method with implicit parameter 4

The String Class

Concatenation

Concatenation in Print Statements

Converting between Strings and Numbers

Substrings

Lecture 10 Clicker Question 3

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);
  1. Agent007
  2. Agent 006
  3. Agent06
  4. Nothing due to a run-time error

German Keyboard

Thai Alphabet

Chinese Ideographs

Reading Input

Lecture 10 Clicker Question 4

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?

  1. name is Agent 007, n is 0
  2. name is Agent, n is 0
  3. name is Agent, n is 0.07
  4. Nothing due to a run-time erro

Reading Input From a Dialog Box

Reading Input From a Dialog Box