日撸代码300行学习笔记 Day 1-3

0.前言

本人曾经学过一定的JAVA基础,但是由于长时间未复习以及使用,逐渐忘掉了这一门语言,目前跟从闵帆老师发布的教程:日撸 Java 三百行(总述)从基础开始学起,此教程为90天,如能坚持下来,自身实力也将进一步变强,希望自己能努力坚持完成。

1.Day 1:实现对JAVA和Eclipse软件以及环境的安装配置

完成Eclipse的安装,学习packge, import 和 println 语句. 其中, package 要与所建的包名(即文件夹名)一致,编写HelloWorld.java.

 Eclipse具体安装步骤详见:Eclipse安装教程

当在命令指示符中出现以下结果时,代表环境配置成功。

日撸代码300行学习笔记 Day 1-3_第1张图片

package cn.itcast.demo1;

public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("Hello World !");
	}
}

运行结果显示为:

2.Day 2:加减乘除基本运算的实现

package cn.itcast.demo2;

public class BasicOperations {
	public static void main(String[] args) {
		int tempFirstInt,tempSecondInt,tempResultInt;
		double tempFirstDouble,tempSecondDouble,tempResultDouble;
		tempFirstInt =20;
		tempSecondInt = 30;
		tempFirstDouble = 3.8;
		tempSecondDouble = 25.8;
		//Addition
		tempResultInt = tempFirstInt + tempSecondInt;
		tempResultDouble = tempFirstDouble + tempSecondDouble;
		System.out.println("" + tempFirstInt + " + " + tempSecondInt + " = " + tempResultInt);
		System.out.println("" + tempFirstDouble + " + " + tempSecondDouble + " = " + tempResultDouble);
		
		//Subtraction
		tempResultInt = tempFirstInt - tempSecondInt;
		tempResultDouble = tempFirstDouble - tempSecondDouble;
				
		System.out.println("" + tempFirstInt + " - " + tempSecondInt + " = " + tempResultInt);
		System.out.println("" + tempFirstDouble + " - " + tempSecondDouble + " = " + tempResultDouble);
				
		//Multiplication
		tempResultInt = tempFirstInt * tempSecondInt;
		tempResultDouble = tempFirstDouble * tempSecondDouble;
				
		System.out.println("" + tempFirstInt + " * " + tempSecondInt + " = " + tempResultInt);
		System.out.println("" + tempFirstDouble + " * " + tempSecondDouble + " = " + tempResultDouble);
				
		//Division
		tempResultInt = tempFirstInt / tempSecondInt;
		tempResultDouble = tempFirstDouble / tempSecondDouble;
				
		System.out.println("" + tempFirstInt + " / " + tempSecondInt + " = " + tempResultInt);
		System.out.println("" + tempFirstDouble + " / " + tempSecondDouble + " = " + tempResultDouble);
				
		//Modulus
		tempResultInt = tempFirstInt % tempSecondInt;
				
		System.out.println("" + tempFirstInt + " % " + tempSecondInt + " = " + tempResultInt);
		
	}
}

 Part 1:加法运算结果

日撸代码300行学习笔记 Day 1-3_第2张图片

 Part 2:减法运算结果

  Part 3:乘法运算结果

 Part 4:除法运算结果

 Part 5:取余运算结果


3. Day3:If语句的使用

package IfStatement;

/**
 * The usage of the if statement.
 * 
 * @author Fan Min [email protected].
 */

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

			// Try a positive value
			tempNumber1 = 100;

			if (tempNumber1 >= 0) {
				tempNumber2 = tempNumber1;
			} else {
				tempNumber2 = -tempNumber1;
			} // Of if

			System.out.println("The absolute value of " + tempNumber1 + " is " + tempNumber2);
			
			// Try a negative value
			// Lines 27 through 33 are the same as Lines 15 through 19
			tempNumber1 =-3;
			if (tempNumber1 >= 0) {
				tempNumber2 = tempNumber1;
			} else {
				tempNumber2 = -tempNumber1;
			} // Of if

			System.out.println("The absolute value of " + tempNumber1 + " is " + tempNumber2);
			
            // Now we use a method/function																																										
			tempNumber1=5;
			System.out.println("The absolute value of " + tempNumber1 + " is " + abs(tempNumber1));
			tempNumber1 = -8;
			System.out.println("The absolute value of " + tempNumber1 + " is " + abs(tempNumber1));
		}// Of main
		
	   /*
		 *********************
		 * The absolute value of the given parameter.
		 * 
		 * @param paraValue The given value.
		 *********************
		 */
		public static int abs(int paraValue) {
			if (paraValue >= 0) {
				return paraValue;
			} else {
				return -paraValue;
			}//Of if
		}// Of abs
}//Of If


Part 1:利用If语句,实现计算一个数的绝对值:

日撸代码300行学习笔记 Day 1-3_第3张图片

 Part 2:利用函数调用,实现使用If语句来计算一个数的绝对值

日撸代码300行学习笔记 Day 1-3_第4张图片

4.总结

目前都是一些基础,在格式以及细节方面需要加强,C和JAVA的输出语句不怎么一样,需要多花时间去熟练使用一下,其他暂时没有什么疑问。

你可能感兴趣的:(java,开发语言)