Java_1_ basic data types and arrays

Source: Internet
Author: User

The basic data types for Java are from low to high by the precision level:

byte short char int long float double

Experiment One:

Conversions between data: char and int (output Greek alphabet)

Public class Program2_1 {
public static void Main (String args[]) {
int startposition = 0, endposition = 0;
char Cstart = ' α ', cend = ' ω ';
startposition = (int) Cstart;
endposition = (int) cend;
System.out.println ("Greek alphabet \ ' alpha" + "\ ' in the order position of the Unicode table:" +startposition);
System.out.println ("Greek alphabet:");
for (int i = startposition; i<= endposition; i++) {
char c = ' + ';
C = (char) i;
System.out.println ("" +c);
if ((i-startposition+1)%10==0)
System.out.println ("");
}
}
}

To give a reverse one:

public class Program2_test1 {
public static void Main (String args[]) {
int startposition = 0, endposition = 0;
Char Cstart = ' A ', cend = ' Z ';
startposition = (int) Cstart;
endposition = (int) cend;
System.out.println (the "English letter \ ' a\ ' position in Unicode is:" +startposition);
System.out.println ("The English alphabet is as follows:");
for (int i = startposition; I <= endposition; i++) {
char c = ' + ';
c = (char) i;
System.out.println ("+c");
}
}
}

Experiment Two:

An array of references and elements:

public class Program2_2 {
public static void Main (String args[]) {
int [] a = {100,200,300};
System.out.println (a.length);
System.out.println (a);
int b[][] = {{1},{1,1},{1,2,1},{1,3,3,1},{1,4,6,4,1}};
System.out.println (b.length);
System.out.println (b[4][2]);
B[4] = A;
System.out.println (b[4][2]);
}
}

Relevant knowledge points:

Arrays are reference variables, for

int a[] = {1,2,3},b [] = {4,5};

The array variables A and B hold the reference, the value of a is the value of 0x35ce36,b is 0X757AEF;

For a one-dimensional array, the value of "array name. Length" is the number of elements in the array, and for a two-dimensional array, the value of "array name. Length" is the number of one-dimensional arrays that he contains.

Experiment Three:

Facilitates and replicates arrays:

Import Java.util.Arrays;
public class Program2_3 {
public static void Main (String args[]) {
int [] a = {1,2,3,4,500,600,700,800};
int [] b,c,d;
System.out.println (Arrays.tostring (a));
b = arrays.copyof (a,a.length);
System.out.println (arrays.tostring (b));
c = arrays.copyof (a,4);
System.out.println (Arrays.tostring (c));
D = Arrays.copyofrange (a,4,a.length);
System.out.println (arrays.tostring (d));
C[C.LENGTH-1] =-100;
D[D.LENGTH-1] =-200;
System.out.println (Arrays.tostring (a));
}
}

To give a reverse one:

Import Java.util.Arrays;
public class Program2_test3 {
public static void Main (String args[]) {
int [] a = {1,2,3,4,5,100,200,300,400,500};
int [] b,c,d;
b = arrays.copyof (A, a.length);
System.out.println (arrays.tostring (b));
c = arrays.copyof (a,5);
System.out.println (Arrays.tostring (c));
D = Arrays.copyofrange (a,5,a.length);
System.out.println (arrays.tostring (d));

}
}

Java_1_ basic data types and arrays

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.