A comment line is an description or explanation of the source code. The command line is also used to hide a line of code. These comment lines are ignored by the compiler.
In Java there are three types of comments. They are,
- Single Line Comment
- Multi Line Comment
- Documentation Comment
Single Line Comment
Single line comment is used to comment only one line of code. Single line comment starts with two forward slash(//).
Example:
class Single_line
{
public static void main(String args[])
{
System.out.println("This is the example for Single line comment"); //This is the printing statement
}
}
Output:
This is the example for Single line comment
Multi Line Comment
To comment more than one line of code Multiline comment is used. Multiline comments starts with /* and ends with */.
Example:
class multiline_comment
{
public static void main(String args[])
{
int a = 10, b = 20, c;
/*
Here the variable a, b, and c are
declared as integer.
*/
c = a+b;
System.out.println("The sum of the value is:" + c);
System.out.println("This is an example for Multiline comment");
}
}
Output:
The sum of the value is:30
This is an example for Multiline comment
Documentation Comment
Documentation comment is used in writing code for project or software package.
Example:
/**
* Prime factor is the factor of the
* given number which is a prime number.
*
* @author Neural Beast
* @version 0.1
*/
import java.util.Scanner ;
class documentation_comment
{
public static void main(String[] args)
{
Scanner sc=new Scanner (System .in);
int n=0;
n=sc.nextInt();
System .out .println ("Prime Factor of" +" "+ n +" "+ "are :");
for(int i=2;i<n/2;i++)
{
for(;n%i==0;){
System .out .print (i+" ");
n=n/i;
}
}
if(n>2)
{
System .out .println (n);
}
}
}
Output:
10
Prime Factor of 10 are :
2 5
Very good info. Lucky me I discovered your blog by accident.
I have book-marked it for later!