SJSU/Udacity CS046

Problem Set 1

  1. Variables
  2. String Length
  3. Objects and Methods
  4. String Lowercase
  5. String Replace
  6. Name In Box
  7. Block Tower

Variables

Write a line of code to (1) declare a variable cost and (2) assign it a value of 12.51. double cost = 12.51;
Write a line of code to (1) declare a String variable course and (2) assign it the value "Udacity". String course = "Udacity";
Given the following line of code:
int count = 1;
write the line of code to assign the value 100 to count.
count = 100;
What is the value of mystery after the following sequence of statements?
int mystery = 10;
mystery = mystery * 2;
mystery = 7 - mystery;
-13

Which of the following are valid variable names in Java?

  1. Valid|Invalid age
  2. Valid|Invalid class
    class is a reserved word.
  3. Valid|Invalid int
    int is a reserved word.
  4. Valid|Invalid 7ofSpaces
    A variable name cannot start with a digit.
  5. Valid|Invalid K@udacity
    A variable name cannot contain symbols such as @.
  6. Valid|Invalid bank account
    A variable name cannot contain spaces.
  7. Valid|Invalid costPerUnit
    Lowercase and uppercase letters are ok.

Given the importance of variable names, which of the following choices is the best name for a variable to hold the area of a square?

  1. a
  2. s
  3. x
  4. areaOfSquare
  5. area

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =