JAVA learning (two) ----- useful in java programming package | method | Usage

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/q303705455/article/details/96626082
  • INPUT LIST:
    . * Classes in java.util
    Scanner Scanner new new SC = ( the System.in );
    int sc.nextInt A = ();

  • Random number to call:

  1. . * the java.lang
    the Random new new RD = the Random ();
    int = A rd.nextInt (20 is) +5; // randomly generates a random number of 5-25
    int b = rd.nextInt (9) * 10 + rd.nextInt (9);

  2. Math.randow (); 0-1 random number (including 0 1 not included)
    , for example: (int) (Math.randow () 10); // random number 0-10
    min Math.randow + ()
    (min-max ); // min-max nonce

  • Call control decimal digits (rounded):
    . * The java.lang
    Classes in java.math *.
    Double F = (9.0 /. 5) * 32 + Celsius;
    Double the BigDecimal new new F1 = (F) .setScale (. 1, BigDecimal.ROUND_HALF_UP). doubleValue ();
    return f1; // one decimal (rounded)

  • Acquisition system timestamp: (1970 to date)
    System.currentTimeMillis (); // Get System milliseconds
    System.nanoTime (); // Get System nanoseconds

  • Math function in
    Math.pow (); a power of
    the Math.abs (); absolute value
    Math.ceil (); rounding up (take 3.1. 4)
    Math.floor (); rounded down (get 3 3.1)

  • Input character
    char c = sc.next () charAt ( 0).;

  • The positive numbers into a string
    String name = String.ValueOf (Integer Name); egg: String s = String.ValueOf (num);

  • Equal to the comparison string (not ==)
    String Next opt = ();
    IF ( "+" the equals (opt).)

  • String inverted
    StringButter sb = new StringButter (str) ; // the string str inverted
    sb.reverse ();
    String str1 = new new String (SB);

  • Dividing the capacity of a string of a string (the string divided) (a string STR, str1 array of strings)
    String [] Name = Original name .split ( ""); egg: String [] str1 = str .split ( "");

Guess you like

Origin blog.csdn.net/q303705455/article/details/96626082