⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 length.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.general;

import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
import jmathlib.core.tokens.Token;
import jmathlib.core.tokens.OperandToken;
import jmathlib.core.tokens.DataToken;
import jmathlib.core.tokens.CharToken;
import jmathlib.core.functions.ExternalFunction;

/**An external function for getting the size of matrices*/
public class length extends ExternalFunction
{
	public OperandToken evaluate(Token[] operands)
	{
		// at least one operand
        if (getNArgIn(operands) != 1)
			throwMathLibException("length: number of arguments != 1");
            
		int length = 0;
		// first operand must be a number
		if(operands[0] instanceof DataToken)
		{
			// get size or argument
			int y = (int)((DataToken)operands[0]).getSizeY();
			int x = (int)((DataToken)operands[0]).getSizeX();
			
			length = Math.max(y,x);
		}
		else if(operands[0] instanceof CharToken)
		{
			length = ((CharToken)operands[0]).toString().length();		
		}

		return new DoubleNumberToken(length);		
	}
}


/*
@GROUP
general
@SYNTAX
answer = length(string) 
answer = length(matrix) 
answer = number(matrix) 
@DOC
Returns the length of a matrix or a string.
@EXAMPLES
<programlisting>
length("test") = 4 
length([1, 2, 3]) = 3
</programlisting>
@NOTES
@SEE
size
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -