Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to use Javadoc Comments in Java program for Documentation ?

Program to use Javadoc Comments in Java for Documentation

/**
 * @see java.util.Date
 * */
import java.util.Date;


/** A simple program demonstrating
 * Java Documentation by placing following 
 * annotations :   
 * @author Jonty
 * @author www.hubberspot.com
 * @version 3.0 
 * */
public class TodaysDate {

/**Entry to main method that prints 
 * todays date. 
 * @param args
 * @exception throws no exceptions
 */
   public static void main(String[] args) {
      System.out.println("Hello, it’s: ");
      System.out.println(new Date());

   }

}




Usage command :
javadoc TodaysDate.java

HTML Generated as:




How to print System Properties through a Java program ?

Program to print System Properties through a Java

public class SystemProperties {

   public static void main(String[] args) {

      System.getProperties().list(System.out);
      System.out.println();
      System.out.println("The User Name property : ");
      System.out.println(System.getProperty("user.name"));
      System.out.println("The Java Library path property : ");
      System.out.println(System.getProperty("java.library.path"));

    }

}




Output of the program :




How to calculate BMI of body in Java ?

Program to calculate BMI of body in Java

import java.util.Scanner;

public class CalculateBMI {
  public static void main(String[] args) {
   
     final double KILOGRAMS_PER_POUND = 0.453; 
     final double METERS_PER_INCH = 0.026;   
    
     Scanner input = new Scanner(System.in);
    
     System.out.print("Enter weight in pounds: ");
     double weight = input.nextDouble();
        
     System.out.print("Enter height in inches: ");
     double height = input.nextDouble();
    
     double weightInKilogram = weight * KILOGRAMS_PER_POUND; 
     double heightInMeters = height * METERS_PER_INCH; 
     double bmi = weightInKilogram / 
      (heightInMeters * heightInMeters);
    
     System.out.printf("Your Body Mass Index is " + bmi);
    
     if (bmi < 16)
       System.out.println("You are seriously underweight");
     else if (bmi < 18)
       System.out.println("You are underweight");
     else if (bmi < 24)
       System.out.println("You are normal weight");
     else if (bmi < 29)
       System.out.println("You are overweight");
     else if (bmi < 35)
       System.out.println("You are seriously overweight");
     else
       System.out.println("You are gravely overweight");
  }
}

Output of the program : 


 
 
© 2021 Learn Java by Examples Template by Hubberspot