Kotlin Foundation 2

Source: Internet
Author: User
Tags exception handling readline


Package android.zhh.com Import android.app.Activity import android.os.Bundle import android.util.Log Import Java.math.BigInteger class Main2activity:activity () {Override fun OnCreate (Savedinstancestate:bundle?) {super.oncreate (savedinstancestate) Setcontentview (r.layout.activity_main2)/** * Function General
        notation *///line1;
        /** * When the content of the LINE1 function is only one line, the function above can be written in this way *///line2 (on);
        /** * When the content of the LINE1 function is only one row, it can also be written as a function expression *///Line3 (for each);
         /** * default parameter and named parameter * Default parameter val PII = 3;
         * Named parameter Canshu (a2=3);
        *///Canshu (a2=3);
        /** * Exception Handling *///Testtry ();

    /** * Function Recursive call * self-drop yourself */Testdigui (10);
    }/** * General wording of the function * */fun line1 (a1:int,a2:int): int{return a1+a2; }/** * When the content of the LINE1 function is only one line, the function above can be written this way */Fun line2 (A1:int,a2:int): INT=A1+A2;
    /** * When the content of the LINE1 function is only one row, it can also be written as a function expression */var line3 ={a1:int,a2:int->a1+a2;
     }/** * default parameter and named parameter * Default parameter val PII = 3;
     * Named parameter Canshu (a2=3);
    */Val PII = 3;
       Fun Canshu (Pi:int = pii,a2:int) {var a3 = pi+a2;
    LOG.E ("111", "a3>>>" +a3);
         }/** * Character A and number conversion */Fun Testnum () {//If the string is something like "a", the type conversion exception var a1= "5";
var a2=5;
Convert a string to a group var A11 = A1.toint ();
    Converts a number to a string var a22=a2.tostring ();
        }/** * Data entered from the keyboard, operation * This is to be entered with the keyboard, do not test here */Fun TestKey () {LOG.E ("111", "first input data");
        var num1=readline ();//return value allowed is null LOG.E ("111", "first input data");
var num2=readline (); //      !! Indicates that the data passed in must not be empty var num11=num1!!.
        ToInt (); var num22=num2!!.
        ToInt ();
    LOG.E ("111", "${NUM11+NUM22}"); }/** * Exception handling * * Fun testtry () {try {var a1:int = 0;
            var a2:int = 1;
        var a3=a2/a1;
        }catch (e:exception) {LOG.E ("111", "program exception" +e.message);  }}/** * Recursive call to function * self-drop yourself */fun Testdigui (num:int): int{if (num==1) {return
        Num
    } return Num*testdigui (num-1);
 }




}
Reference Video:
Http://yun.itheima.com/course/266.html?1708ku-hda6

SOURCE Download:

http://download.csdn.net/download/zhaihaohao1/10178134
Reference Document: http://www.kotlindoc.cn







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.