📄 moremath.java
字号:
/* * cs101 Math utilities * $Id: MoreMath.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $ * * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group. * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the * CS101 homepage</a> or email <las@ai.mit.edu>. * * Copyright (C) 1996 Massachusetts Institute of Technology. * Please do not redistribute without obtaining permission. */package cs101.util;/** * cs101.util.MoreMath is an extension of the java.lang.Math library. * <br> * Copyright 1996 Massachusetts Institute of Technology * * @author Todd C. Parnell, tparnell@ai.mit.edu * @author Lynn Andrea Stein, las@ai.mit.edu * */public class MoreMath { /** * Generate a random int between 0 and range. Note that if range is * negative, this returns a negative number. * * @param range desired maximum int. */ public static int randomInt(int range) { return (int) Math.round(Math.random() * range); } /** * Returns the square of the input. No checks are made for MaxInt overflow. * * @param x the number to square */ public static int square(int x) { return(x * x); } /** * Returns 1 if the input is positive, -1 if it is negative, and 0 otherwise. * * @param x the number to get the sign of */ public static int sign(int x) { if(x == 0) { return(0); } else if(x > 0) { return(1); } return(-1); } /** * Prevent instantiation */ private MoreMath() {}}/* * $Log: MoreMath.java,v $ * Revision 1.1.1.1 2002/06/05 21:56:32 root * CS101 comes to Olin finally. * * Revision 1.5 1999/08/17 18:37:02 emarcus * Added sign and square methods. * * Revision 1.4 1998/07/24 17:19:30 tparnell * Placate new javadoc behavior * * Revision 1.3 1998/07/21 19:38:19 tparnell * added more javadoc & private MoreMath() * * Revision 1.2 1998/06/03 19:47:44 tparnell * added header, javadoc and logging * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -