Last active
September 1, 2021 05:50
-
-
Save kyleburton/809a2e51f772567e05c096c2baa54651 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test { | |
public static String evenOrOdd(int val) { | |
if (0 == (val % 2)) { | |
return "even"; | |
} | |
return "odd"; | |
} | |
public static String evenOrOdd(long val) { | |
if (0 == (val % 2)) { | |
return "even"; | |
} | |
return "odd"; | |
} | |
public static int getoptNumLoops( String [] args, int defaultValue) { | |
if (args.length > 0) { | |
try { | |
return Integer.parseInt(args[0]); | |
} | |
catch (Exception e) { | |
// ignore or otherwise disregard the exception, one of the | |
// worst possilbe things a professional software engineer can | |
// do :-D | |
} | |
} | |
return defaultValue; | |
} | |
public static void main ( String [] args ) { | |
java.util.Random rnd; | |
int numLoops = getoptNumLoops(args, 4); | |
System.out.println("doubles between 0 and 1"); | |
for (int ii = 0; ii < numLoops; ++ii) { | |
System.out.println("java.lang.Math.random() = " + java.lang.Math.random()); | |
} | |
System.out.println(""); | |
System.out.println("doubles scaled to integers from 1 to 100"); | |
for (int ii = 0; ii < numLoops; ++ii) { | |
int val = (int)(java.lang.Math.random() * 100.0); | |
System.out.println("java.lang.Math.random() = " + val + " " + evenOrOdd(val)); | |
} | |
System.out.println(""); | |
System.out.println("int type"); | |
rnd = new java.util.Random(); | |
for (int ii = 0; ii < numLoops; ++ii) { | |
int val = rnd.nextInt(); | |
System.out.println("rnd.nextInt() = " + val + " " + evenOrOdd(val)); | |
} | |
System.out.println(""); | |
System.out.println("long type"); | |
rnd = new java.util.Random(); | |
for (int ii = 0; ii < numLoops; ++ii) { | |
long val = rnd.nextInt(); | |
System.out.println("rnd.nextLong() = " + val + " " + evenOrOdd(val)); | |
} | |
System.out.println(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment