zoukankan      html  css  js  c++  java
  • No.1_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='
    ';
            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 + "不是闰年。");
            }
            
        }    
    
    }

     输出结果:

     1 我能学好JAVA!!
     2 GOOD BYE LIULIU~
     3 Hi world!
     4 747.9852000598908
     5 125
     6 a
     7 ★请输入变量A的值8
     8 请输入变量B的值9
     9 A=8B=9
    10 执行变量互换,位移只能是整型
    11 A=9B=8
    12 a是奇数
    13 a:78,b:17,c:97,d:521,e:9
    14 请输入一个年份:(闰年规则,能被4或400整除,不能被100整除。)
    15 2016
    16 2016 是闰年
  • 相关阅读:
    表达式求值
    火柴排队(归并)
    POJ 3254 压缩状态DP
    ZOJ 3471 压缩状态DP
    Boost IPC Persistence Of Interprocess Mechanisms 例子
    TCO 2014 Round 1A
    Google Code Jam 2014 Qualification 题解
    STL set_difference set_intersection set_union 操作
    b_zj_特征提取(map记录上一个特征运动的次数)
    b_zj_最大连续的相同字符子串的长度(双指针+找突破点)
  • 原文地址:https://www.cnblogs.com/sunshine-habit/p/5249189.html
Copyright © 2011-2022 走看看