01 - Introduction to Java - Exercise 2
Task 1 - String variables
Create a new project and call it
VariablesExercise
.Within the
main
method, declare twoString
variables -firstName
andlastName
.Assign values to the variables above.
Create another variable called
name
and assign it a concatenated value of the two previous variables.Print out
name
.
Task 2 - Numbers
Comment out the code from the previous task.
Create two integer variables, call them
num1
andnum2
.Assign them a valid literal value.
Print out their sum.
Create another integer variable -
result
. Assign it the result of division betweennum1
andnum2
. Does it work? Can you fix it?Create another integer variable -
num3
and assign it a value 8.Print out the value of
num3++
.Print out the value of
num3
.Print out value of
++num3
.Is there any difference?
Task 3 - User input
Comment out all your code from the previous task.
Research how to read user input from the terminal - Read and Write User Input in Java | Baeldung
Hint: Don't forget the import : import java.util.Scanner;
Ask the user for their first name and their last name.
Print out a greeting using their name.
Ask the user for two numbers (you may need to do it one by one)
Print out their sum.