Java study memo 2 with Progate

Type story

It seems that there are quite a lot of types of data. I thought about int and numbers, but to be exact, they are "integers". Numbers with a decimal point are classified as double type. Calculations between int types return results as int types, and calculations between double types return as double types.

System.out.println(5/2);            2    //int type
System.out.println(5.0/2.0);        2.5  //double type

Note: hand_splayed_tone2:

Since it is not possible to process data types with different data types with + etc., it is necessary to convert ** types **.

Type conversion

Automatic type conversion

//String type + int type
System.out.println("today" + 6 + "It's the moon")
=>("today" + "6" + "It's the moon")
int type is automatically converted to String type

int type and double type ⇒ double type

Because int type is automatically converted to double type.

Forced conversion (cast)

If you want to get an accurate answer (including after the decimal point) in the calculation of integers, perform forced type conversion. For example, when you want to perform 10/4 calculation conversion → Both are int type, so either value should be double type. Then, automatic type conversion is applied, both become double type, and the obtained value also becomes double type. If there is no type conversion, the decimal point will be cut to 2.

System.out.println((double)10/4);
Change 10 from int type to double type
                     //2.5



Recommended Posts

Java study memo 2 with Progate
Study Java with Progate Note 1
Java Silver Study Method Memo
Java memo
Personal memo: Metaprogramming with Java reflection
[Study session memo] Java Day Tokyo 2017
java anything memo
Let's study Java
Java Silver memo
java, maven memo
[Java ~ Variable definition, type conversion ~] Study memo
Java SE 7 memo
java anything memo 2
[Java] Study notes
Java 8 study (repeatable)
Java study memorandum
Study Java Silver 1
Java specification memo
Java pattern memo
Study session memo: Kansai Java Engineers Association 8/5 --Selenium
Install java with Homebrew
Install Java with Ansible
Java Silver Study Day 1
java basic knowledge memo
Java learning memo (method)
Java Kuche Day memo
Comfortable download with JAVA
java se 8 programmer Ⅰ memo
Java paid private memo
Switch java with direnv
Dot installation study memo 01
Java study # 1 (typical type)
java lambda expression memo
(Memo) Java for statement
My Study Note (Java)
Download Java with Ansible
Java lambda expression [memo]
Let's scrape with Java! !!
Java learning memo (interface)
[Java] Implicit inheritance memo
Build Java with Wercker
Java learning memo (inheritance)
java competitive programming memo
[Memo] Java Linked List
Endian conversion with JAVA
Easy BDD with (Java) Spectrum?
Study Java # 2 (\ mark and operator)
Use Lambda Layers with Java
Java multi-project creation with Gradle
Java (WebSphere Application Server) memo [1]
Getting Started with Java Collection
[Java] Variable name naming memo
Java memo (standard class) substring
Java Config with Spring MVC
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
Play Framework Study Memo Database ①
[Template] MySQL connection with Java
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
Java learning memo (data type)