Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing java/05-staticmethods/Positive by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Write a class <code>Positive</code> with a static method <code>isPositive()</code>
that takes one integer argument, and returns the boolean value <code>true</code> if 
the argument is positive, and <code>false</code> otherwise.
Public permissions remove
Engine
Template / Reference solution
 
public static \[boolean]\ \[isPositive]\(\[int]\ \[x]\) {
\[
   return (x > 0);
]\
}
// basic tests
public static void main (String[] args) {
   StdOut.println("126 is positive? " + isPositive(126));
   StdOut.println("-126 is positive? " + isPositive(-126));
   StdOut.println("0 is positive? " + isPositive(0));
   StdOut.println("1 or -1 is positive? " 
               + (isPositive(-1) || isPositive(1)));
}
Java test suite
See manual
 
testMain();
test("isPositive", randgen.nextInt(100)+1);
test("isPositive", -randgen.nextInt(100)-1);
Solution visibility remove


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.