Java Basics (i)---data types &math methods & casts

Source: Internet
Author: User
Tags arithmetic

Data types and various math class methods

1  Public classHelloWorld {2      Public Static voidMain (String args[]) {3         //familiar with various data types, forcing type conversions to look at levels4         Final intvar = 100;5         intVarr = 200;6         floatm = -21.5f;7         Doublep = 21.234;8         BooleanJudge =true;9         Charch = ' A ';Ten         Longnum = 625; One          ShortNUM1 = 12; A         byteA = 1; -String str = "I am a great boy!"; -          the         //arithmetic operations depend on various static methods of the math class -System.out.println (Math.Abs (m));//Absolute Value -System.out.println (Math.sin (a));//Trigonometric Functions -SYSTEM.OUT.PRINTLN (Math.asin (0.5));//Inverse trigonometric Function +System.out.println (Math.sqrt (Var));//Open Square Heel -SYSTEM.OUT.PRINTLN (MATH.CBRT (num));//Open Cube Root +System.out.println (Math.Round (m));//Rounding ASystem.out.println (Math.ceil (1.5));//Rounding up atSystem.out.println (Math.floor (1.9));//Rounding down -System.out.println (Math.max (100, 50));//take a large value -System.out.println (Math.min (12.3, 13.3));//take a small value -System.out.println (Math.random () +1);//Generate random numbers -System.out.println (Math.pow (2, 10));//exponential arithmetic: calculating - B (latter) power of a (former) inSystem.out.println (MATH.LOG10 (100));//Logarithmic operations -     } to}
The above code eclipse is compiled by
Forcing type conversions

Welcome Message Discussion ^w^!

Java Basics (i)---data types &math methods & casts

Related Article

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.