0% found this document useful (0 votes)
5 views1 page

Unit3Assignment Question1 PDF

Uploaded by

easonshi686
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)
5 views1 page

Unit3Assignment Question1 PDF

Uploaded by

easonshi686
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

package JAVA;

import java.util.Scanner;// Import all classes from the java.util scanner

public class Assignment1 {


public static void main(String[] args) {
// Create a Scanner to read user input
Scanner scanner = new Scanner(System.in);
// Prompt user to enter weight
System.out.print("Please enter your weight: ");
// Read the weight value input by the user
double weight = scanner.nextDouble();
// Check if the weight is less than 0 and print error message if true
if (weight < 0) {
System.out.println("Invalid weight");
}
// Check if the weight is less than 60 and print relevant message if true
else if (weight < 60) {
System.out.println("You are lightweight");
}
// Check if the weight is less than or equal to 80 and print relevant message if true
else if (weight <= 80) {
System.out.println("You are medium weight");
}
// If weight is greater than 80, print the heavyweight message
else {
System.out.println("You are heavyweight");
}
// Close the Scanner to release resources
scanner.close();
}
}

You might also like