1.字符串练习:
public class ChangeCharTest{ public static void main(String[] args){ System.out.println("书名\t作者\t价格\t销量"); System.out.println("三国\t罗贯中\t120\t1000"); /*\\ 优化*/ System.out.println("书名\t作者\t价格\t销量\n三国\t罗贯中\t120\t1000"); } }
总结:
2.文档注释(常用)
/** * @author [liu] * @version [1.0] */ public class DocTest{ public static void main(String[] args) { System.out.println("hello"); } }
D:\Java_code>javadoc -d D:\Java_code -author -version DocTest.java
3.输出如下格式,且只能使用一个System.out.println
public class ChangeCharTest{ public static void main(String[] args){ String name = "刘颜"; int age = 23; float grade = 130.5; char gender = '女'; String hobby = "网球、看书"; System.out.println("姓名\t年龄\t成绩\t性别\t爱好\n"+name+"\t" +age+"\t"+grade+"\t"+gender+"\t"+hobby); } }
总结:
4.运算符
public class ChangeCharTest{ public static void main(String[] args){ System.out.println(10/4); -->2 System.out.println(10.0/4); -->2.5 double a = 10/4; System.out.println(a); -->2.0 } }
总结:
5.i++和++i。注意对于自身赋值,会出现一个临时变量去保存数值
i++:①先将i赋值给temp,此时temp=1;②自加,此时i=2;③最后把temp赋值给i,此时i=1
public class test{ public static void main(String[] args) { int i = 1; i = i++; System.out.println(i); } }
++i①自加,此时i=2;②再将i赋值给temp,此时temp=2;③最后把temp赋值给i,此时i=2
public class test{ public static void main(String[] args) { int i = 1; i =++i; System.out.println(i); } }