0% found this document useful (0 votes)
15 views

Lab 2 Error

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lab 2 Error

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SSK1102 2023/2024-1

UNIVERSITI PUTRA MALAYSIA


FACULTY OF HUMANITIES, MANAGEMENT AND SCIENCE

LAB 2 – Individual

LAB OBJECTIVE:
The main objective for this lab is to introduce student to types of error, display pattern, and
create simple program to calculate BMI. Student able to identify syntax error, logic error, and
run-time error based on given coding. Student also can understand how to display pattern
using syntax System.out.print or System.out.println. Student can write simple program to
calculate BMI.

DURATION:
1 week / 3 hours

INTRODUCTION:

In coding, errors are the mistake that programmers do, and it can be fixed. There are 3 types of
error; syntax error, logic error, and run-time error. (refer note slide 137 for details).

LAB QUESTION / ACTIVITIES:

1. Give 1 example of syntax error.


2. Give 1 example of logic error.
3. Give 1 example of run-time error.
4. What are the difference between System.out.print or System.out.println?
5. Write this coding and fix all the error.

import java.util.Scanner;
public class BMICalculator {
public static void main(string[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter their weight in kilograms
System.out.println("Enter your weight in kilograms:");
double weight = scanner.nextDouble();
// Prompt the user to enter their height in meters
System.out.println("Enter your height in meters:");
double height = scanner.nextDouble();
// Calculate the user's BMI
double bmi = weight / height;
// Display the user's BMI
System.out.println("Your BMI is " + bmi);
// Determine the user's BMI category
if (Bmi > 18.5) {
System.out.println("You are underweight.");
} else if (bmi < 25) {
System.out.println("You are normal weight.");
} else if (bmi < 30) {
System.out.println("You are overweight.");
} else {
System.out.println("You are obese.");
}
}
}
1

You might also like