Lab 2 task 2
Mon Mar 11 2024 18:10:14 GMT+0000 (Coordinated Universal Time)
Saved by
@brhm_lifter
package pl.pp;
import java.util.Scanner;
public class AgeInSeconds {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);
// Ask the user for their age in years
System.out.print("Enter your age in years: ");
int ageInYears = scanner.nextInt();
// Close the scanner to prevent resource leak
scanner.close();
// Calculate the age in seconds
long ageInSeconds = (long) ageInYears * 365 * 24 * 60 * 60;
// Display the age in seconds with proper description
System.out.println("My age in seconds: " + ageInSeconds);
}
}
content_copyCOPY
Comments