Day 1 code exercise _ Basics

Source: Internet
Author: User

// The content on the first day includes Java environment configuration, data type explanation, and data type calculation. In the environment configuration, You need to input javac.exe in any directory under the lifecycle command window to display the correct display results. You need to set public class test {public static void main (string [] ARGs) in the environment variable) {// Reserved Words and keywords cannot be used. * variable Definition Format: data type variable name = initialization value variable must be assigned a value first, and then use * // variable to divide by data type, it can be divided into basic data types (eight types) and reference data types (three types) int M = 10; // variable naming method int N; n = 12; int sum = m + N; char A = 'a'; double SJD = 12.0; double sjd1 = SJD; // INTEGER: byte (8bit) Short (16bit) int (32bit) Long (64bit) byte b1 = 12; // byteb1 = 128; value overflow short S1 = 1 28; int I1 = 125; long L1 = 128; long L2 = 1234567890l; // beyond the int expression range, add "L" or "L" // float (32bit) double (64bit) Double d1 = 123.31; D1 = 123.0; float F1 = 12.7f; // define a float variable/* character type represents a character in the program. A single character occupies two bytes of char (16 bit) enclosed in single quotes; */Char C1 = 'a'; // string STR = "AB"; char C2 = '1 '; char C3 = 'ha'; system. out. println ("C3"); char C4 = '\ n'; // wrap char C5 =' \ T'; // tabulation system. out. println ("AB" + C4 + "cd"); system. out. println ("AB" + C5 + "cd"); // unicode encoded char C6 = '\ u1112'; system. out. println ("C6 =" + C6); // Boolean only has two values: true and false. The value cannot be null (null is the default value for all referenced type variables) // It is usually used in Process Control by Boolean Bol = true; If (BOL) {system. out. Println ("Hello \" Handsome \ "");} else {system. out. println ("");} // conversions between basic data types (except Boolean) // 1.1 automatic conversions: small capacity variables and large capacity of the variable between the calculation, small capacity of the automatic conversion to large capacity data type byte b2 = 12; int I2 = 10; int I3 = i2-b2; system. out. println ("I3 =" + I3); float F2 = 12.5f; short S2 = 10; float F3 = F2 + S2; system. out. println ("F3 =" + F3); int S3 = S2 + 10; double S4 = S3 + 10.3; long L4 = 1223; // automatic type conversion // float F4 = 12.33; // compilation fails. // when the byte char short operation is performed, the calculation result is int; int I4 = B2 + S2; int I5 = B2 + C1; int I6 = C1 + S2; system. out. println ("I4 =" + I4); system. out. println ("I5 =" + I5); system. out. println ("I6 =" + I6); char C7 = 'a'; int i7 = C7 + 1; int i8 = C1 + 1; system. out. println ("i7 =" + i7); system. out. println ("i8 =" + i8); // forcibly convert the data type with a large capacity to a data type with a small capacity, use a forced type conversion character // forced conversion may result in loss of precision double DD1 = 12.3; float ff1 = (float) DD1; system. out. println ("ff1 =" + ff1); int I9 = 128; byte B10 = (byte) I9; system. out. println ("I9 =" + I9); system. out. print ("SJD =" + SJD); system. out. print (C4); system. out. println ("sjd1 =" + sjd1); system. out. println ("n =" + n); system. out. println ("sum =" + sum); system. out. println ("helloworld! ");} // Defines a run method public void run () {system. Out. println (" running! ") ;}Public void tojump (){}}


This article is from the "First day of course" blog, please be sure to keep this source http://5453607.blog.51cto.com/5443607/1528492

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.