Java基础入门|基于美国大学教材

这篇博客是为经济学转码计算机专业的学生准备的,基于美国大学教材,讲解了Java编程的基础知识,包括import、public class、注释、输入/输出、方法、变量作用域、Scanner、assert、条件语句、循环、位操作符、数组、数据类型等内容,并提醒了初学者在编程时容易犯的错误。
摘要由CSDN通过智能技术生成

前言

本人陆本经济学转码计算机在读,目前就读于威斯康星麦迪逊大学。基于中美教育的一些不同,特开设此专栏协助学习,也供有需要的有缘人使用。

该专栏会串联琐碎的知识,将它们按照“当一个人正在写程序时会需要注意什么、了解什么”的顺序而编写。

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值