The JavaTM Tutorial
Previous Page Lesson Contents Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Learning the Java Language
Lesson: Language Basics

Answers to Questions and Exercises: Expressions, Statements, and Blocks

Questions

  1. Question: What are the data types of the following expressions, assuming that i's type is int?
    i > 0
    i = 0
    i++
    (float)i
    i == 0
    "aString" + i
    
    Answer:
    i > 0            [boolean]
    i = 0            [int]
    i++              [int]
    (float)i         [float]
    i == 0           [boolean]
    "aString" + i    [String]
    
  2. Consider the following expression:
    i--%5>0
    
    1. Question: What is the result of the expression, assuming that the value of i is initially 10?
      Answer: false.
    2. Question: Modify the expression so that it has the same result but is easier for programmers to read.
      Answer: (i-- % 5) > 0

Exercises

  1. Exercise: Write a program to confirm your answers to Questions 2a and 2b.
    Solution: OperatorEx(in a .java source file)

Previous Page Lesson Contents Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.