Sunteți pe pagina 1din 5

Java Labs

Each weeks labs should be held in a separate folder: E.g. lab1.

Create this new folder each week in your user directory on the hard drive - E.g.
c:\users\g001234\lab1.

Save all files you work on in this lab to this folder.

At the end of class please ensure you take a backup of this folder save to one drive or create a
folder on the u:\ drive to copy this weeks folder to.

All Exercises should be completed using TextPad.

To compile your code in TextPad, hit the ctrl key and 1 key. Hold down the ctrl key, while holding
that key down press 1.

To run your compiled program, .class file, in TextPad, hit the ctrl key and 2 key. Hold down the ctrl
key, while holding that key down press 2.

For all programs please insert a header similar to the following:

For all exercises, follow the instructions to implement the solution.


Introduction
In this weeks lab we will be focussing on creating basic computer programs to write data to a screen.

Section A
Exercises 1 to 9. Complete All.

Exercise 1:
Your first Java Program as part of this module. Type the following code below into TextPad, save it
and run it:

This program should produce the following output:

Exercise 2:
Create a new class myName, which prints your name to the screen. Example output as follows:

Exercise 3:
Create a new class exercise3, which prints two lines to the screen. Example output as follows:
Exercise 4:
Create a new class exercise4, which prints three lines to the screen. Example output as follows:

Exercise 5:
Create a new class exercise5, which prints four lines to the screen. Example output as follows:

Exercise 6:
Create a new class exercise6, which prints five lines to the screen. Example output as follows:

Exercise 7:
The aim of this exercise is to use multiple statements to print a single line of text. Create a class
exercise7, which uses both the System.out methods print and println to give the following output:
Exercise 8:
Create a class exercise8, which uses two statements to print two lines of text to the screen. Example
output as follows:

Exercise 9:
Create a class exercise9, which uses three statements to print two lines of text to the screen.
Example output as follows:

Section B
Exercises 10 to 12. Complete All exercises.

See below for help in completing this exercise:

Exercise 10:
Create a class exercise10, which uses one statement to print multiple lines of data. An example
output is as follows:
Exercise 11:
Create a class exercise 11, which uses one statement to print multiple lines of data. You may
consider use a tab escape sequence (t). An example output is as follows:

Exercise 12:
Compile a list of three questions, which you can pose to at least two of your fellow students. Create
a class exercise12, which collates the responses you receive and outputs them to the screen in a
readable format. For example, the output could be similar to the following:

Use as many statements as you like but do include some escape sequences.

Section C
Exercise 13 only.

Exercise 13:
Create a class exercise13, which uses one printf statement to print three lines. An example output is
as follows:

S-ar putea să vă placă și