Java学习第五天 <变量、常量、作用域><基本运算符><自增自减运算符、初识Math类><逻辑运算符、位运算符><三元运算符及小结><包机制><JavaDoc文档cmd命令生成与IDEA生成>

变量、常量、作用域

public class Demo07 {
    public static void main(String[] args) {
        //int a,b,c;
        //int a=1,b=2,c=3;注意程序可读性
        String name="zhengtu";
                char x='X';
                double pi=3.14;
​
    }
}

public class Demo08 {
    //类变量 static,命名首字母小写和驼峰原则
    static double salary=2500;
​
 //实例变量,从属于对象;如果不自行初始化,这个类型默认值 0 0.0
    //布尔值默认 false
    //除了基本类型,其余都是null
   String name;
   int age;
//main()方法,方法名首字母小写和驼峰原则
    public static void main(String[] args) {
        //局部变量,在方法main大括号里生效,必须声明和初始化值,命名首字母小写和驼峰原则
        int i=10;
        System.out.println(i);
​
        Demo08 demo08 = new Demo08(); //变量类型 变量名字 =new Demo08()
​
        System.out.println(demo08.age);// demo08.age.sout
        System.out.println(demo08.name);
​
        System.out.println(salary);//类变量 static,去掉static报错
    }
​
    //其他方法
    public void add(){
​
    }
}

public class Demo09 {
    //常量多用大写和下划线
    static final double PI=3.14;//static final可调换,修饰符不存在先后顺序
    public static void main(String[] args) {
        System.out.println(PI);
​
    }
}

基本运算符

public class Demo01 {
    public static void main(String[] args) {
        //二元运算符
        //ctrl+D复制当前行到下一行
        int a=10;
        int b=20;
        int c=25;
        int d=25;
​
        System.out.println(a + b);
 System.out.println(a - b);
 System.out.println(a * b);
 System.out.println(a /(double) b);//0.5不转会舍去
​
​
    }
}

public class Demo02 {
    public static void main(String[] args) {
        long a=1321321321231321213L;
        int b=123;
        short c=10;
        byte d=8;
        //各类型相加,有long double时,结果取long double,没有时候取int类
        System.out.println(a + b + c + d);//long类型
        System.out.println(b + c  + d);//int
        System.out.println( c + d);//int
    }
}

public class Demo03 {
    public static void main(String[] args) {
        //关系运算符返回结果: 正确 错误 布尔值
        int a=10;
        int b=20;
        int c=21;
        System.out.println(c % a);//   c/a=2....1取余数,模运算
        System.out.println(a > b);
        System.out.println(a < b);
        System.out.println(a == b);
        System.out.println(a != b);
        System.out.println(a = b);//赋值
​
    }
​
}

自增自减运算符、初识Math类

public class Demo04 {
    public static void main(String[] args) {
        //++  --  自增  自减
        int a=3;
        int b=a++;//a=a+1 先赋值,后自增
        System.out.println(a);//4
        int c=++a;//先自增,后赋值
​
        System.out.println(a);//5
        System.out.println(b);//3
        System.out.println(c);//5
        //幂运算 2^3=8 很多运算会使用工具类来操作
        double pow = Math.pow(2, 3);//Math.pow(2, 3) alt+回车两次
        System.out.println(pow);
​
​
​
    }
​
​
}

逻辑运算符、位运算符

public class Demo05 {
    public static void main(String[] args) {
        //与 或 非
        boolean a = true;
        boolean b=false;
​
        System.out.println("a&&b:"+(a&&b));//a&&b:false
        System.out.println("a||b:"+(a||b));//a||b:true
        System.out.println("!(a&&b):"+!(a&&b));//!(a&&b):true
​
        //短路运算
        int c=5;
        boolean d=(c<4)&&(c++<4);//前面短路
        System.out.println(d);
        System.out.println(c);
    }
}

public class Demo06 {
    public static void main(String[] args) {
        /*位运算与二进制有关
        A=0011 1100
        B=0000 1101
        A&B=0000 1100
        A|B=0011 1101
        A^B=0011 0001  相同为0,不同为1
        ~B=1111 0010  B取反
​
        2*8=16 2*2*2*2
        
        <<左移(左移1次相当于*2) >>右移(/2)
        0000 0000  0
        0000 0001  1
        0000 0010  2
        0000 0011  3
        0000 0100  4  2左移1位
        0000 1000  8  2左移2位
        0001 0000  16 2左移3位
         */
        System.out.println(2<<3);//16,左移三位,相当于*2*2*2
    }
}

三元运算符及小结

public class Demo07 {
    public static void main(String[] args) {
        int a=10;
        int b=20;
        a+=b;//a=a+b
        a-=b;//a=a-b
        System.out.println(a);
​
        //字符串连接符  +
        System.out.println(a+b);
        System.out.println(""+a+b);//字符串在前,全拼接
        System.out.println(a+b+"");//字符串在后,先运算
​
    }
}

public class Demo08 {
   //三元运算符
   public static void main(String[] args) {
       //x?y:z 如果x为真,则结果为y,否则结果为z
       int score=80;
       String type=score<60?"不及格":"及格";
       //if
       System.out.println(type);
   }
}

包机制

包的本质就是文件夹

包名 com.zhengtu.XXX

在src右键 package 取名 com.operator 也可拖运

package必须放最上面,去掉会报错

导入包

import com.operator.Demo01

导入base所有包

import com.base.*;

看看阿里巴巴开发手册

JavaDoc生成文档

/*                    加在类上为类注释
* @author zhengtu     作者名
* @version 1.0        版本号
* @since 1.8          需要最早使用的jdk版本
* */
public class DOC {
    String name;
​
    /**               /**回车后自动生成,加在方法上为方法注释
     *
     * @param name    参数名
     * @return        返回值情况
     * @throws Exception  异常抛出情况
     */
    public String test(String name) throws Exception{
        return name;
    }
​
}

通过命令行生成文档

1.右键DOC,open in explorer

2.打开cmd

3.输入javadoc -encoding UTF-8 -charset UTF-8 Doc.java

       java命令 让中文显示更正常的参数 Java文件编译成文档

4.文件夹里可以看到生成的文档

 

通过IDEA生成文档

1.IDEA 菜单 Tools->Generate JavaDoc 项里面

 2.以模块(Module)为主,Locale 可选填项填写zh_CN,“Other command line arguments:”可选填项,填     -encoding UTF-8 -charset UTF-8 -windowtitle "你的文档在浏览器窗口标题栏显示的内容" -link http://docs.Oracle.com/javase/7/docs/api

3.JavaDoc 生成完毕,即可在其根目录下找到 index.html 文件,打开它就可以看到我们自己的标准 JavaDoc API 文档啦

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值