zoukankan      html  css  js  c++  java
  • JAVA(入门)笔记2

    1.else子句与同一块中离得最近的未匹配if子句相匹配

    2.System.exit(0);

       该方法为静态方法,调用这个方法可终止程序,参数0表示程序正常结束

    3.Math.random();

       返回一个随机双精度值D,如:0.0≤D<1.0

    使用例子:

        (int)(Math.random()*10)    返回一个随机一位整数(0~9)

    4.switch语句

       switch(swith-expression)                   swith-expression:必须能计算出一个char,byte,short或int值        

       {

           case value1:statement(s)1;           value必须是常量,变量可不行

                              break;                        break立即终止真个switch语句

           case value1:statement(s)1;

                              break;

    ........

           default:statement(s)-for-default;

        }

    5.条件表达式

       布尔表达式?表达式1表达式2;

    6.格式化控制台输出

        System.out.printf(format,item1,item2,....,itemn);

                                    format:子串和格式描述符构成的字符串

    7.消息框中显示格式化输出

        String.format(format,item1,item2,...,itemn);

    比较:

        format方法返回格式化的字符串

        printf方法显示格式化字符串      

    如:

       ①System.out.printf("a+b=%d",(a+b));

       ②String string=String.format("a+b=%d",(a+b));

       ③JOptionPane.showMessageDialog(null,String.format("a+b=%d",(a+b)));

    29.描述符前加“-”,表示项目在特定区域输出时   左对齐;“+”时默认为  右对齐

    30.%用来标记描述符,要在格式字符串里输出%,使用%%

    31.赋值运算符是右结合的(先计算赋值运算符右边的式子)

         如:a=b+=c=5↔a=(b+=(c=5))

    32.运算顺序:从左往右最高,运算符的优先级其次

         若有修改量值得副作用,运算先从左往右;

         若没有,则按照运算符的优先级运算

    例:

         ①int a=0;

           int x=a+(++a);

           则从左往右运算,结果为:1,不是2

         ②int a=0;

            int x=++a+a;

           则从左往右,结果为:2

  • 相关阅读:
    oracle 数据库服务名怎么查
    vmware vsphere 6.5
    vSphere虚拟化之ESXi的安装及部署
    ArcMap中无法添加ArcGIS Online底图的诊断方法
    ArcGIS中字段计算器(高级计算VBScript、Python)
    Bad habits : Putting NOLOCK everywhere
    Understanding the Impact of NOLOCK and WITH NOLOCK Table Hints in SQL Server
    with(nolock) or (nolock)
    What is “with (nolock)” in SQL Server?
    Changing SQL Server Collation After Installation
  • 原文地址:https://www.cnblogs.com/KeenLeung/p/2374879.html
Copyright © 2011-2022 走看看