首页 > 编程知识 正文

返回绝对值的函数,excel怎么输入绝对值函数

时间:2023-05-06 07:17:17 阅读:24559 作者:4650

**文章摘要*

1、用于获取表达式绝对值的绝对值函数。

2、实现绝对值函数、降序升序输出。

一.绝对值函数的使用说明

绝对值函数是JDK的Math.java实现方法,用于确定表达式的绝对值。

其实现非常简单,源代码如下。

//*

* returnstheabsolutevalueofan { @ codeint } value。

* If the argument is not negative,the argument is returned。

* If the argument is negative,thenegationoftheargumentisreturned。

*

*

notethatiftheargumentisequaltothevalueof

* {@link Integer#MIN_VALUE},the most negative representable

* {@code int} value,the result is that same value,which is

*否定。

*

* @ paramatheargumentwhoseabsolutevalueistobedetermined

* @ returntheabsolutevalueoftheargument。

*/

公共统计数据中心(inta ) {

返回(A0 )? -a : a;

}

二、绝对值特性及其运用。

1、正数的绝对值是它本身。

2、负数的绝对值是其倒数。

3、零的绝对值是它本身。

绝对值:自减法函数按照绝对值,按降序升序排列。

int number=6;

System.out.println ('原始值输出:');

wile(number=-6 ) {

number --;

system.out.print(number ' );

}

system.out.println (绝对值输出() );

number=6;

wile(number=-6 ) {

number --;

system.out.print (math.ABS (number ) ');

}

输出结果:

原始值输出:

5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7

绝对值输出:

5 4 3 2 1 0 1 2 3 4 5 6 7

三.个案

1、背景:输出以下模式。

a

B A B

C B A B C

dbabbcddbbcd

E D C B A B C D E

F E D C B A B C D E F

G F E D C B A B C D E F G

2、分析:

1、a为中心点

2、各行,降序、升序

3、字母可以换算成整数,' A'=65。 在中,每行的第一个输出字符是' a '行数。

4、每行左右对称,每行输出字符数=行数*2 1 (字母a );

3、实现

1、实现分析中的1~3个步骤。 以‘a’为中心点,按降序排列,然后按升序输出各行的图案。

//调用

打印(5;

//*

*降序后按升序实现

* @param row

*/

隐私声明

for(intI=0; i2*row 1; I ) {

intprintchar='a'math.ABS(row-I );

system.out.print (() ) printChar ) ');

}

}

输出如下。

F E D C B A B C D E F

2、在步骤4中,每行的输出字符数=行数*2 1 (字母a ),如下所示。

各行应该显示的字母以外的部分,打印空格。 逻辑控制如下。

for(intj=0; j2*row 1; j ) {

//逻辑输出字符。 降序、升序逻辑输出的字母

intprintchar='a'math.ABS(row-j );

//“逻辑控制字符”大于“规定输出字符”时:

if(printcharfirstchar )

//输出空格

System.out.print (' );

}else{

//输出字符

system.out.print (() ) printChar ) ');

}

}

3、完整代码:

//完全调用

打印窗口(7;

//*

*按反序输出字母大写字母

*

* @param row行

*/

私有状态语音打印机withrow

for(intI=0; I

//规定输出文字。 每行第一个显示的字符

int firstChar='A' i;

for(intj=0; j2*row 1; j ) {

//逻辑输出字符。 降序、升序逻辑输出的字母

intprintchar='a'math.ABS(row-j );

//“逻辑控制字符”大于“规定输出字符”时:

if(printcharfirstchar )

//输出空格

System.out.print (' );

}else{

//输出字符

system.out.print (() ) printChar ) ');

}

}

//输出返回

System.out.println (;

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。