Java Language Basics-type conversion

Source: Internet
Author: User

1. Automatic type conversion

Automatic type conversions, also known as implicit conversions, can convert an int variable to a float type.

1  Public classConver {2      Public Static voidMain (string[] args) {3         4         byteMyByte = 127;5         intMyint = 150; 6         floatMyfloat = 452.12f; 7         CharMyChar = 10; 8         DoubleMyDouble = 45.46546; 9System.out.println ("byte-type and float-type data is calculated as:" + (MyByte +myfloat));Ten         /*outputs the result of the Operation*/ OneSystem.out.println ("byte type and int type data are calculated as:" + MyByte *Myint); ASystem.out.println ("Byte-type and char-type data is calculated as:" + MyByte/MyChar); - System.out -. println ("Double-type and char-type data results in:" + (MyDouble +MyChar)); the     } -}

2. Forcing type conversions

Coercion type conversions are also known as explicit type conversions.

Convert different data types.

The syntax format is as follows: (type name) the value to convert

int a = (int) 23.23; long y = (long) 234.34; int b = (int) ' d ';

3. Code comments

Comments are for people, not for computers.

Java annotations are divided into three types;

1, single-line comment; 2, multiline comment; 3. Document comment.

1. Single-line Comment

As a single-line comment marker, everything from the symbol "//" until the line breaks is ignored as comments.

The format is as follows://comment Content

int age;//define int variable for saving ages

2, multi-line Comment

/* */For multiline comment markers. /* and/* must appear in pairs.

The syntax format is as follows:

/*

#¥%......&

%#%............

/*

3. Documentation Comments

/** * * marks the document comment.

The contents of the symbol/** * * are treated as Javadoc documents by Java.

Java Language Basics-type conversion

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.