Day 03

一、学习内容:

1.文档注释

2.基本if语句(绝对值求解)

3.简单的函数调用

package basic;

public class Ifstatement {
	public static void main(String args[]) {
		int tempNumber1, tempNumber2, tempNumber3;

		// 给一个正值
		tempNumber1 = 8;

		// 使用if语句
		if (tempNumber1 >= 0) {
			tempNumber2 = tempNumber1;
		} else {
			tempNumber2 = -tempNumber1;
		}
		System.out.println("the absolute value of " + tempNumber1 + " is " + tempNumber2);

		// 给一个负值
		tempNumber1 = -3;
		if (tempNumber1 >= 0) {
			tempNumber2 = tempNumber1;
		} else {
			tempNumber2 = -tempNumber1;
		}
		System.out.println("the absolute value of " + tempNumber1 + " is " + tempNumber2);

		// 用下面给定的abs函数实现绝对值运算
		tempNumber1 = -10;
		System.out.println("the absolute value of " + tempNumber1 + " is " + abs(tempNumber1));
		tempNumber1 = -5;
		tempNumber3 = abs(tempNumber1);
		System.out.println("the absolute value of " + tempNumber1 + " is " + tempNumber3);
		tempNumber1 = 9;
		System.out.println("the absolute value of " + tempNumber1 + " is " + abs(tempNumber1));

	}

	// 文档注释
	/**
	 *********************
	 * 计算参数的绝对值
	 * 
	 * @param paraValue The given value.
	 *********************
	 */

	// 定义abs函数
	public static int abs(int paravalue) {
		if (paravalue >= 0) {
			return paravalue;
		} else {
			return -paravalue;
		}
	}

}

 二、实现结果

Day 03

三、遇到的问题

1.函数调用及定义掌握的不够

2.文档注释有些地方不了解

 

上一篇:通讯录管理系统(C++版)


下一篇:MATLAB算术运算符和常用函数