/
01 - Introduction to Java - Exercise 2

01 - Introduction to Java - Exercise 2

Task 1 - String variables

  1. Create a new project and call it VariablesExercise.

  2. Within the main method, declare two String variables - firstName and lastName.

  3. Assign values to the variables above.

  4. Create another variable called name and assign it a concatenated value of the two previous variables.

  5. Print out name.

Task 2 - Numbers

  1. Comment out the code from the previous task.

  2. Create two integer variables, call them num1 and num2.

  3. Assign them a valid literal value.

  4. Print out their sum.

  5. Create another integer variable - result. Assign it the result of division between num1 and num2. Does it work? Can you fix it?

  6. Create another integer variable - num3 and assign it a value 8.

  7. Print out the value of num3++.

  8. Print out the value of num3.

  9. Print out value of ++num3.

  10. Is there any difference?

Task 3 - User input

  1. Comment out all your code from the previous task.

  2. 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;

  1. Ask the user for their first name and their last name.

  2. Print out a greeting using their name.

  3. Ask the user for two numbers (you may need to do it one by one)

  4. Print out their sum.