Summary of Java Math.random and import (Calendar)

I'm taking notes of the jammed parts based on the learning site paiza. Math.random() Get double type random numbers in the range of 0.0 to less than 1.0. The return value is double.

double number = Math.random();

Output result スクリーンショット 2020-08-12 13.21.42.png

When you want to get a value from 1 to 100.

double number = Math.random() * 100 + 1;

This time, "* 100" is ** how many numbers to put out, the number of ranges ** "+1" is ** how many numbers start, the lower limit value ** Can be entered by specifying the range.

If you want to get the value in the range of 4 to 10 (7 numbers), display as follows.

double number = Math.random() * 7 + 4;

If you want the return value to be an integer, cast it.

int num = (int)number;
Or
int num = (int)(Math.random());

import (Calendar) A class library that gets the date.

Description example:

import java.util.Calendar;
public class Main {
	public static void main(String[] args) {
	    Calendar calendar = Calendar.getInstance();
	    int seireki = calendar.get(Calendar.YEAR);
	    
	    System.out.println(seireki + "Year");
	}
}

Get the month

int month = calendar.get(Calendar.MONTH);

Get the day

int data = calendar.get(Calendar.DATE);

Sites referenced for import [Java] A brief explanation for beginners! Take import from a different angle.

I also wanted to know the class to get time by the way, so the site listed [With sample program] Summary of how to get Java time!

Recommended Posts

Summary of Java Math.random and import (Calendar)
Summary of Java support 2018
[Java] Personal summary of classes and methods (basic)
Summary of FileInputStream and BufferedInputStream
Summary of ToString behavior with Java and Groovy annotations
[Java11] Stream Summary -Advantages of Stream-
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
[Java] Summary of for statements
Summary of Java Math class
Advantages and disadvantages of Java
[Java] Summary of control syntax
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations
[For beginners] Summary of java constructor
Java release date and EOL summary
About fastqc of Biocontainers and Java
Summary of [Java silver study] package
[Java] Judgment of identity and equivalence
Summary of object-oriented programming using Java
A brief summary of DI and DI containers
[Java Silver] Summary of access modifier points
Summary of in-house newcomer study session [Java]
How to make a Java calendar Summary
After 3 months of Java and Spring training
[java] Summary of how to handle char
Summary of changes other than JEP of Java10
[Java] Personal summary of conditional statements (basic)
[Java] Inheritance and structure of HttpServlet class
Summary of hashes and symbols in Ruby
[Java / Swift] Comparison of Java Interface and Swift Protocol
[Java] [Maven3] Summary of how to use Maven3
Java Summary of frequently searched type conversions
[Java] Contents of Collection interface and List interface
Basics of java basics ② ~ if statement and switch statement ~
Discrimination of Enums in Java 7 and above
Display Japanese calendar and days of the week using java8 standard class
Summary of good points and precautions when converting Java Android application to Kotlin
Java knowledge summary
[java] Summary of how to handle character strings
Java Generics Summary
Summary of Java environment settings for myself [mac]
Java related summary
[Java] The confusing part of String and StringBuilder
I compared the characteristics of Java and .NET
Japanese Advent Calendar Java Edition of Synthetic Sequences
JAVA: Realizes generation and scanning of various barcodes
Basics of threads and Callable in Java [Beginner]
Java 8 documentation summary
[Java] Classification memo of compilation error and run-time error
Date () and Calendar ()
XXE and Java
Summary of Japan time setting and display method
Java 11 document summary
Import files of the same hierarchy in Java
[Java] Overview of Java
Java enables extraction of PDF text and images
[Java] Convert and import file values with OpenCSV
[Java] How to use Calendar class and Date class
Summary of frequently used commands in Rails and Docker