Comments

Purpose

  1. To write comments in your program so the reader can better understand it.
  2. To have the compiler skip over a desired part of your program.

Symbols

//

Any code that subcedes this on the SAME line of code becomes a comment
Note: When you start a new line after //, it does not effect it

public static int swap(int num1, int num2){
  int temp; //I use the temp to store num1's value since the original num1 changes after num1 = num2

  temp = num1;
  num1 = num2;
  num2 = temp;

  return num1, num2; // returns the swapped ints

/*…*/

Any code between these 2 signs becomes a comment
Advantage: Could make MORE THAN 1 LINE a comment

public static int swapThree(int num1, int num2, int num3){
  int temp1,
       temp2;
 
  temp1 = num1;
  temp2 = num2;
  num1 = num3;
  num2 = temp1;
  num3 = temp2;
 
/*To swap 3 numbers with ONE temp:
  num1 = num3;
  num3 = num2;
  num2 = temp1;
*/

Javadoc

/**

*

*

*/

/**  
* Swap - a simple class for demonstrating the use of javadoc comments.  
* @author  Eden Melloul
* @version 1.0
* The following program swaps numbers
*/ 
public static int swap(int num1, int num2){
  int temp; 

  temp = num1;
  num1 = num2;
  num2 = temp;

  return num1, num2;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License