Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab 01
Objectives
1.
2.
3.
Learn the basics of Java and try out several sample programs.
Learn how to declare variables and deal with arithmetic expressions.
Deal with String variables and methods.
Preparatory Work
1.
2.
3.
Exercise 1
a.
b.
c.
d.
Compile the program (using a Java compiler) and correct any compilation errors.
... > Lab01 > javac Lab01_Ex1.java
e.
1/2
Exercise 2
a.
b.
Declare and initialize another two variables: double y = 2.3 and float z = 5.2f.
Display the result of each of the following arithmetic expressions using the
System.out.println() statement. Complete the table.
Arithmetic Expression
Result
Precedence/Priority Rules
x + y * z
20.959999561309814
*, +
x / y * z
20.34782534060271
/, *
x / 2 + y / 2
/,+
/,+
1 + x / 2
%,%,*,+
*,+
/,+
2 - x % 2
x % 5 * 3 + 1
(y + 3) * 2
z / (1 + 1)
Exercise 3
a.
b.
str4 = ...;
System.out.println(str4);
System.out.println(...);
str1 = ...;
System.out.println(str1);
}
}
2/2