Lab 2: Introduction to Java Applications PDF
Document Details
2025
COMP1116
Tags
Summary
This document is a Java programming lab exercise for COMP1116, Semester 1, 2024-2025. The lab focuses on creating a Java program that calculates the product of three integers input by the user.
Full Transcript
Lab 2: Introduction to Java Applications COMP1116 – Computer Programming Semester 1, 2024-2025 The lab session of this course is divided into two activities, Instructor-led and Students Tasks. LAB OBJECTIVES By completing this lab activity, you will be able to: Write a complete java program...
Lab 2: Introduction to Java Applications COMP1116 – Computer Programming Semester 1, 2024-2025 The lab session of this course is divided into two activities, Instructor-led and Students Tasks. LAB OBJECTIVES By completing this lab activity, you will be able to: Write a complete java program. Use output statement. Use input statement. Calculate the product of three integers In this exercise, we will write a complete program that calculates and prints the product of three integers. 1. Launch IntelliJ IDEA editor. 2. In the New Project wizard, name the project CalculateProducts, and click Finish. 3. Create a class named CalculateProducts 4. Inside the created class, create the main method as shown below: 5. State that a program will calculate the product of three integers. 6. Create a Scanner called input that reads values from the standard input. 7. Declare the variables x, y, z and result to be of type int. 8. Prompt the user to enter the first integer. Then, Read the first integer from the user and store it in the variable x. 9. Prompt the user to enter the second and third integers. Then, Read the second and third integers from the user and store it in the variables y and z. 10. Compute the product of the three integers contained in variables x, y and z, and assign the result to the variable result. 11. Use System.out.printf to display the message "Product is" followed by the value of the variable result. 12. Compile and run the above Java program as shown below: