Вы находитесь на странице: 1из 2

Create your own workspace directory and structure it as: source dir and class di

r
Source directory should only have .java files.
Compile these into class file, output creation should happen only in class dir.
Exercise 1: An Important Message
In this exercise you will write a working program in Java to display an importan
t message on the
screen.
Inject few syntax errors into the program and study compiler outputs.
Try to output content on stdout using cat command for .java as well as .class fi
le.
Write short note on CLASSPATH variable, and showcase its experimentation.
Exercise 2: More Printing
Produce the following output:
+------------------------+
|
|
| Thapar STORE
|
|
|
| 2016-08-01
04:00PM |
|
|
| Pens: 20
|
| Price/pen:
Rs.12.00 |
|
|
| Total:
Rs.240.00|
|
|
+------------------------+
Exercise 3: Printing Choices
Demonstrate difference between print and println.
Exercise 4: Escape Sequences and Comments
Have you thought about what might happen if we wanted to display a quotation mar
k on the screen? Since everything we want to display is contained between quotat
ion marks in the println() statement, putting a quote inside the quotes would be
a problem.
Most programming languages allow for escape sequences , where you signal with some
sort of escape character that the next character you see shouldn t be handled in t
he normal way.
Demonstrate use of escape sequences.
Exercise 5: Saving Information in
Variables
A variable is a name that refers to a location that holds a value.
Variables in Java have four major differences from math variables:
1. Variable names can be more than one letter long.
2. Variables can hold more than just numbers; they can hold words.

3. You have to choose what type of values the variable will hold when the variab
le is first created.
4. The value of a variable (but not its type) can change throughout the program.
For example,the variable score might start out with a value of 0, but by the en
d of the program, score might hold the value 413500 instead.
Output the following via using variables:
The variable x contains 10
The value 400 is stored in the variable y.
The experiment took 4.71 seconds.
A favorite irrational # is Euler's number: 2.718281828459045
Hopefully you have more than $1.89!
My name's Mr./Ms. FirstYear
Exercise 6: Mathematical Operations
a is 10, b is 27
a+b is 37
a-b is -17
a+b*3 is 91
b/2 is 13
b%10 is 7
x is 1.1
x*x is 1.2100000000000002
b/2 is 13.0
one is computer
two is programming
Both is computerprogramming
Exercise 7: Getting Input from a
Human
Exercise 8: Storing the Human s
Responses
Exercise 9: Calculations with User
Input
Exercise 10: Boolean Expressions
Exercise 11: Comparing Strings
Exercise 12: Making Decisions with If
Statements
Exercise 13: If Statements with Strings
Exercise 14: Mutual Exclusion with
Chains of If and Else
Exercise 15: Nested If Statements
Exercise 16: Making Decisions with a
Big Switch

Вам также может понравиться