Sie sind auf Seite 1von 6

J A VA B A S I C S

Tra i ni n g Assi gn men ts


Program Code
Version

0.1

Effective date

11/05/2011

Hanoi, 05/2011

Training Assignments

Java Basics

RECORD OF CHANGES
*A - Added M - Modified D - Deleted
Date

Changes

A*
M, D

Contents

Version

11/05/2011

Create new

All

0.1

79e-BM/NS/HDCV/FSOFT v1/0

Internal use

2/6

Training Assignments

Java Basics

Contents
Day 1: Assignments................................................................................................................ 4
Assignment 1:..................................................................................................................... 4
Assignment 2:..................................................................................................................... 4
Assignment 3:..................................................................................................................... 4
Assignment 4:..................................................................................................................... 5
Assignment 5:..................................................................................................................... 5
Assignment 6:..................................................................................................................... 5
Assignment 7:..................................................................................................................... 6
Assignment 8:..................................................................................................................... 6

79e-BM/NS/HDCV/FSOFT v1/0

Internal use

3/6

Training Assignments

Java Basics

Day 1: Assignments
Assignment 1:
Objective:
Problem Description:

Write a program that gives the output: "Hello World!


Assumptions:
Questions to answer:
Estimated time: 5 mins

Assignment 2:
Objective:
Problem Description:

What is the output of the following code?

Assumptions:
Questions to answer:
Estimated time: 5 mins

Assignment 3:
Objective:
Problem Description:

Write a program that does the following:

Declare and initializes variables m and n to 100 and 200 respectively


Under the condition, if m equals zero, it displays the appropriate result.

If m is greater than n, it displays the appropriate result.

Check whether the value of n is even or odd

79e-BM/NS/HDCV/FSOFT v1/0

Internal use

4/6

Training Assignments

Java Basics

Assumptions:
Questions to answer:
Estimated time: 10 mins

Assignment 4:
Objective:
Problem Description:

1. Explain how the intern() method in java.lang.String can improve runtime performance
of a program.
Hint: see API documentation for String class, especially method intern()
Assumptions:
Questions to answer:
Estimated time: 10 mins

Assignment 5:
Objective:
Problem Description:

In some languages the operators "&&" (and) and "||" (or) are short circuited. That is
once the result of a boolean expression of &&s and ||s is known, the remainder of the
boolean expression will not be evaluated. For example in (( x > x ) && ( z == y) ) the
expression (z ==y) will not be evaluated. Write a Java method that will test if boolean
expressions in Java are short circuited. Explain how your program will determine if
boolean expressions are short circuited.
Assumptions:
Questions to answer:
Estimated time: 15 mins

Assignment 6:
Objective:
Problem Description:

In both parts of the problem do not perform any IO in the methods. Provide output to
show that your program runs.
a) Write a Java method that has a float parameter and returns the float
converted to a string.

79e-BM/NS/HDCV/FSOFT v1/0

Internal use

5/6

Training Assignments

Java Basics

b) Write a Java method that has a string parameter and returns the string
converted to an int. Assume that the string represents an integer base 10 in
the correct range for an int.
Assumptions:
Questions to answer:
Estimated time: 30 mins

Assignment 7:
Objective:
Problem Description:

Write a Java program to find root of this equation:


ax2 + bx + c = 0
Assumptions:
Questions to answer:
Estimated time: 30 mins

Assignment 8:
Objective:
Problem Description:

2. Write a Java program to count the number of 1 bit in a binary string which was
gotten from a given int number. For example:

Give an int number 0, we got a binary 0, then result will be 0.

Give an int number 7, we got a binary 111, then result will be 3.

Give an int number 8, we got a binary 1000, then result will be 1.

Give an int number 10, we got a binary 1010, then result will be 2.

Assumptions:
Questions to answer:
Estimated time: 30 mins

79e-BM/NS/HDCV/FSOFT v1/0

Internal use

6/6

Das könnte Ihnen auch gefallen