Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do I comment this Java code? I'm new.?

I'm new to Java and honestly what I see when I look at this are methods. I'm not even 100% what to write...I've commented what I think I know to be right, the methods at the top. How would I comment the lines toward the bottom? What am I doing in Java class again? C# is my buddy.

int value;

//constructor

MyInteger(int newValue) { value = newValue; }

// get method that returns value

public int getValue() { return value; }

//returns true if even

public static boolean isEven(int num) { return (num%2 == 0); }

//returns true if odd

public static boolean isOdd(int num) { return !isEven(num); }

//returns true if a prime

public static boolean isPrime(int num) {

for (int f=2; f<num/2; f++) if (num%f==0) return false;

return true;

}

public static boolean isEven(MyInteger n) { return n.isEven(); }

public static boolean isOdd(MyInteger n) { return n.isOdd(); }

public static boolean isPrime(MyInteger n) { return n.isPrime(); }

public boolean isEven() { return isEven(value); }

public boolean isOdd() { return isOdd(value); }

public boolean isPrime() { return isPrime(value); }

public boolean equals(int n) { return (value == n); }

public boolean equals(MyInteger n) { return equals(n.getValue()); }

public static int parseInt(String s) { return Integer.parseInt(s); }

public static int parseInt(char[] s) { return parseInt(new String(s)); }

}

Update:

lol I know how to make a comment, // works also. I'm just asking if I appropriately commented the first section and how to comment the second section.

1 Answer

Relevance
Still have questions? Get your answers by asking now.