Thursday-Understanding of common APIs

Source: Internet
Author: User
Tags mathematical functions

1, Math class: Mathematical classes Define a number of mathematical functions, such as sin, COS, exp, ABS and so on. The Math class is a tool class that plays a very important role in solving some of the math-related problems.

This class has two static properties: E and pi. E represents the E 2.7182818 in mathematics, while Pi represents Pi 3.1415926.

The methods in the math class are static methods, and calling a static method can be called directly using the class name. The method name is not required to create an object of the class first

2. Date class: Indicates a specific moment, accurate to milliseconds

3. DateFormat Class: Abstract class that formats and analyzes dates or times in a language-independent manner.

4. SimpleDateFormat class: Specific classes for formatting and analyzing dates in a language-related way

5. Calendar class: Abstract class that provides methods for converting between specific moments and a set of calendar fields such as year, MONTH, Day_of_month, HOUR, and provides methods for manipulating calendar fields, such as getting the date of the next week.

6. Random class: Stochastic is a pseudo-random algorithm, which is random with rules. At random, the origin of the random algorithm is called the seed number (seed), the number of seeds on the basis of a certain transformation, resulting in the need for random numbers.

instance of the Date class: Import Java.text.SimpleDateFormat;

SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");

Df.format (new Date ());//Get current time

Example of Calendar class: Import Java.util.Calendar;

Calendar C = calendar.getinstance ();
int year = C.get (calendar.year);
int month = C.get (calendar.month) +1;
int date = C.get (calendar.date);
int hour = C.get (Calendar.hour_of_day);
int minute = C.get (Calendar.minute);
int second = C.get (Calendar.second);
System.out.print (Year + "-" + month + "-" + date+ "" +hour+ ":" +minute+ ":" +second ");

Instances of the Random class:

public class Suijishu {public static void main (string[] args) {//TODO auto-generated method stubdouble a = Math.random (); int dice = (int) (6*a+1); System.out.println (DICE), switch (DICE) {case 1:system.out.println ("bad luck, 1 points"); Break;case 2:system.out.println ("Poor luck , 2 points "); Break;case 3:system.out.println (" Lucky, 3 points "), Break;case 4:system.out.println (" Good luck, 4 points "); Break;case 5: System.out.println ("Good luck, 5 points"), Break;case 6:system.out.println ("very good luck, 6 points");

  

Thursday-Understanding of common APIs

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.