Home : Course Map : Chapter 2 : Java : Exercises
Exercises
JavaTech
Course Map
Chapter 2

Introduction
Essentials
Structure

Keywords
Primitive Types
Comments
Literals
Expressions
Operators
Statements
Casts & Mixing
Strings
Console Output 
   Demo
Exercises

    Supplements
Conditional: if-else
Repetitions
Flow Control

Java vs C/C++
JVM Instructions 1

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

These exercises explore details of the language and provide practice at writing applets and applications. You can use the Starter_App1.java or Starter_Applet1.java frameworks to create application or applets to carry out the exercises.

  1. Create a program to practice creating strings for printing out numerical values. Write code to print

    1. Example values of all 8 primitive types.
    2. Create a variable such as x, set it to value, and then use the "+" append operator to print out the value in an equation as in "x=3".
    3. Create 9 integer variables and assign each to a particular value. Then print the variables out in a matrix of 3 rows by 3 columns.

  2. What will be the the values of i,j,k after the following statements labeled 1, 2, 3 and 4? Write a program to test your predictions.:

       int i = 1;
       int j= 3;
       int k;
       k = j-- + ++i;    // 1

       i = 1; j = 3;
       k = ++i + j--;    // 2

       j = 3;
       k = j-- + ++j;    // 3

       j = 3;
       k = --j + j++;    // 4

  3. Predict what the output of the following code snippet will be and then test your prediction with a program

       int j=0;
       int i=1;
       for(; i < 2; i++) j++;
       System.out.println("i= "+ i + " j= "+j);


       i=0;
       j=5;
       do{
          j--;
       } while( (i++) < 5);
       System.out.println("i= "+ i + " j= "+j);


       j=5; i=0;
       while( (i++) < 5){
          j--;
       }
       System.out.println("i= "+ i + " j= "+j);


 

References & Web Resources

Latest update: Dec.11.2003

            Tech
Arithmetic Ops
Math Class
More on Integers
FP : Overview
FP : Java  
  
Demo 1
More Mix/Cast
  Demo 2
Exercises

           Physics
Differential Eq.
Euler Method
  
Demo 1
Predictor-Corrector
  
Demo 2
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.