欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

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

时间:2023-07-11

0.前言

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

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

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

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

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

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;//AdditiontempResultInt = tempFirstInt + tempSecondInt;tempResultDouble = tempFirstDouble + tempSecondDouble;System.out.println("" + tempFirstInt + " + " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " + " + tempSecondDouble + " = " + tempResultDouble);//SubtractiontempResultInt = tempFirstInt - tempSecondInt;tempResultDouble = tempFirstDouble - tempSecondDouble;System.out.println("" + tempFirstInt + " - " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " - " + tempSecondDouble + " = " + tempResultDouble);//MultiplicationtempResultInt = tempFirstInt * tempSecondInt;tempResultDouble = tempFirstDouble * tempSecondDouble;System.out.println("" + tempFirstInt + " * " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " * " + tempSecondDouble + " = " + tempResultDouble);//DivisiontempResultInt = tempFirstInt / tempSecondInt;tempResultDouble = tempFirstDouble / tempSecondDouble;System.out.println("" + tempFirstInt + " / " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " / " + tempSecondDouble + " = " + tempResultDouble);//ModulustempResultInt = tempFirstInt % tempSecondInt;System.out.println("" + tempFirstInt + " % " + tempSecondInt + " = " + tempResultInt);}}

 Part 1:加法运算结果

 Part 2:减法运算结果

  Part 3:乘法运算结果

 Part 4:除法运算结果

 Part 5:取余运算结果


3、Day3:If语句的使用

package IfStatement;public class If {public static void main(String args[]) {int tempNumber1, tempNumber2;// Try a positive valuetempNumber1 = 100;if (tempNumber1 >= 0) {tempNumber2 = tempNumber1;} else {tempNumber2 = -tempNumber1;} // Of ifSystem.out.println("The absolute value of " + tempNumber1 + " is " + tempNumber2);// Try a negative value// Lines 27 through 33 are the same as Lines 15 through 19tempNumber1 =-3;if (tempNumber1 >= 0) {tempNumber2 = tempNumber1;} else {tempNumber2 = -tempNumber1;} // Of ifSystem.out.println("The absolute value of " + tempNumber1 + " is " + tempNumber2); // Now we use a method/functiontempNumber1=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 public static int abs(int paraValue) {if (paraValue >= 0) {return paraValue;} else {return -paraValue;}//Of if}// Of abs}//Of If

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

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

4.总结

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

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。