前言
本人陆本经济学转码计算机在读,目前就读于威斯康星麦迪逊大学。基于中美教育的一些不同,特开设此专栏协助学习,也供有需要的有缘人使用。
该专栏会串联琐碎的知识,将它们按照“当一个人正在写程序时会需要注意什么、了解什么”的顺序而编写。
When we are coding…
import
(后面补充)
public class
class 可以理解为blueprint 即创建一整个总的程序做什么,这个会影响到Java的file name,记住class的命名是uppercase
Comments
javadoc(/** */)
Javadoc is a tool that parses specially formatted multi-line comments to generate program documentation in HTML format. The program documentation is also known as an API (application programming interface). Those special doc comments begin with /** and end with */; the beginning two asterisks distinguish doc comments from regular comments.
·在写程序时,一个好的做法是在[public class]、每个[method]前都添加javadoc, 有没有空行都ok
·为了好看,doc comments是与所解释的内容左对齐的
·Doc comments consist of an overall description, and a tags section.
/**
* write overall description This method returns the maximum number among the five parameters.(e.x.)
*(white space to distinguish between description and bolck tags)
* @author IAMWOOD (e.x.)Block tag
* @version 1.0 (e.x.)
*/ (这里需要注意一下“*”、“/”之间没有空格,有空格会出现错误), 所以回车后记得删除
易犯的错:
(1)/**后直接写description
(2)忽略“/**”与“*/”中间的“*”
(3)description写完后没有空行,注意description是一个英语陈述句,所以有句号
(4)Block tag 用“:”、“.” , 如: @author :xxx.
(5)忘记换行再*/结尾
Block comments (/* */)
Line comments (// ...)
input / output
注意是 System!!
注意要求是print 还是println1!!
System.out.println(); 会得到一个回车,即end in new line
System.out.printf(); to works by taking a format string and one or more arguments, and using them to generate a formatted string. The % sign indicates that a placeholder is being used, and the .2f format specifier indicates that the value should be formatted as a floating-point number with two decimal places.
double pi = 3.145;System.out.printf("The value of pi is %.2f", pi);
The value of pi is 3.15
Mathod
Identify Mathod
两种mathod方法
static void :无返回值
static String/int/double :有返回值
关于mathod的变量问题
scope
a variable is accessible everywhere within the closest set of curly brackets. For example:
class Test
{ // s not accessible here, outside of brackets where s was declared