How to convert a value of a different type and assign it to another variable

grammar

Data type variable name = (data type) Variable name on the side to be assigned

public class Main {
	public static void main(String[] args) {

        double rand = Math.random(); * 100;

        //Assign a variable to a variable
		int number = (int)rand;

		System.out.println(number);
	}
}

bonus

It is also possible to assign the Math function at the same time as the variable definition

In that case, enclose it in ().

int game_num = (int)(Math.random() * 10 + 1);
System.out.println("The number of games" + game_num + "Pieces");

Recommended Posts

How to convert a value of a different type and assign it to another variable
[ruby] How to assign a value to a hash by referring to the value and key of another hash
Assign a Java8 lambda expression to a variable and reuse it
How to change the value of a variable at a breakpoint in intelliJ
[Java] How to convert one element of a String type array to an Int type
How to convert A to a and a to A using AND and OR in Java
How to create a header or footer once and use it on another page
Sample code to assign a value in a property file to a field of the expected type
[Java] How to convert a character string from String type to byte type
How to move another class with a button action of another class.
How to deal with different versions of rbenv and Ruby
How to convert LocalDate and Timestamp
How to read a file and treat it as standard input
[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
[Swift5] How to communicate from ViewController to Model and pass a value
[Java] How to convert from String to Path type and get the path
How to pass the value to another screen
[Rails] How to create a table, add a column, and change the column type
Basics of Java development ~ How to write a program (flow and conditional branching) ~
Find a value that is convenient to have a method and make it a ValueObject
How to ZIP a JAVA CSV file and manage it in a Byte array
[Ruby] How to convert from lowercase to uppercase and from uppercase to lowercase
[Android] How to convert a character string to resourceId
Ruby How to convert between uppercase and lowercase
[Ruby] How to use the map method. How to process the value of an object and get it by hash or symbol.
[Ruby] When you want to assign the result obtained by conditional branching to a variable and put it in the argument
How to find the total value, average value, etc. of a two-dimensional array (multidimensional array)-java
Pass arguments to the method and receive the result of the operation as a return value
I want to call a method of another class
[Java] Types of comments and how to write them
java: How to write a generic type list [Note]
Convert the array of errors.full_messages to characters and output
[Java] How to get the maximum value of HashMap
Cannot convert value of type'DocumentSnapshot' to expected argument type'QueryDocumentSnapshot'
How to serialize and deserialize LocalDateTime type with GSON
How to convert a file to a byte array in Java
A memorandum when I investigated how to convert from Epoch Time to Date type in Scala
How to add another project as Maven library with CircleCI and use it for build
How to encode and calculate bitmaps of active user IDs with different dates in MaxCompute
How to type backslash \
How to write a migration from Rails datetime type to date type
How to use a foreign key with FactoryBot ~ Another solution
How to change the setting value of Springboot Hikari CP
[Java] Difference between assignment of basic type variable and assignment of reference type variable
[Ruby] How to retrieve the contents of a double hash
Java Language Feature and How it Produced a Subtle Bug
I tried to convert a string to a LocalDate type in Java
Mapping to a class with a value object in How to MyBatis
How to develop and register a Sota app in Java
How to join a table without using DBFlute and sql
How to check the extension and size of uploaded files
How to make th: value of select have multiple values
[jsoup] How to get the full amount of a document
How to create and launch a Dockerfile for Payara Micro
Convert Excel to Blob with java, save it, read it from DB and output it as a file!