No.1 java语言基础_学习笔记

import java.util.Scanner;

public class HelloWorld {
    static final double PI=3.14;
    static int x=125;
    /** 
     * 文档注释,程序名称:HelloWorld
     * 开发时间:2016-03-07
     * 作者:嘿嘿
     * */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println("我能学好JAVA!!");
        System.out.println("GOOD BYE LIULIU~");
        //变量
        String var = "Hi world!";
        System.out.println(var);
        
        int x=521,y=123;
        float i=1.23f;
        double j=100.123d;
        System.out.println(x+y+i*PI+j);
        System.out.println(HelloWorld.x);
        
        char str='a';
        char str1='\n';
        char str2='\u2605';
        System.out.print(str);
        System.out.print(str1);
        System.out.print(str2);
        
        //运算符
        Scanner scan=new Scanner(System.in);
        System.out.print("请输入变量A的值");
        long  a=scan.nextLong();
        System.out.print("请输入变量B的值");
        long b=scan.nextLong();
        System.out.println("A=" + a +"B=" + b);
        System.out.println("执行变量互换,位移只能是整型");
        
        a=a^b;
        b=b^a;
        a=a^b;
        System.out.println("A=" + a +"B=" + b);
        String check=(a % 2 ==0)?"a是偶数":"a是奇数";
        System.out.println(check);
        
        //强制类型转换
        int liua=(int)78.33;
        long liub=(long)17.8;
        int liuc=(int)'a';
        short liud=521;
        byte liue=(byte)liud;                //byte最大值 127,造成数据溢出
        System.out.println("a:"+liua+",b:"+liub+",c:"+liuc+",d:"+liud+",e:"+liue);
        
        //判断输入的年份是不是闰年
        System.out.print("请输入一个年份:(闰年规则,能被4或400整除,不能被100整除。)");
        long year=scan.nextLong();
        if( year % 4 ==0 && year % 100 != 0 || year % 400 ==0 ){
            System.out.println(year + " 是闰年");
        }
        else
        {
            System.out.println(year + "不是闰年。");
        }
        
    }    

}

 

你可能感兴趣的:(No.1 java语言基础_学习笔记)