This presentation is the property of its rightful owner.
Sponsored Links
1 / 69

数据类型及其运算 PowerPoint PPT Presentation


  • 89 Views
  • Uploaded on
  • Presentation posted in: General

数据类型及其运算. 标识符. 标识符 : 为程序中的各个元素进行命名 . 一般地,在 Java 中标识符是以字母、下划线( _ )、美元符号( $ )等其它货币符号 ( 如 £ , ¥ ) 开始的一个字符序列,后面可以跟字母、下划线、美元符号、数字等字符。 Java 语言使用 Unicode 字符集 标识符是大小写敏感的,没有最大长度的限制,不能和关键字相同. 标识符. 总体来说定义标识符可以使用的字符包括: 大小写字母、数字; Unicode 字符集中编号大于 0xC0 的所有字符。

Download Presentation

数据类型及其运算

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


5566490


5566490

  • : .

  • Java _$(, )

  • JavaUnicode


5566490

    • Unicode0xC0

    • Character.isJavaIdentifierStart() trueCharacter. isJavaIdentifierPart()true

    • Body_test$hello

    • 5Testhello*world#class

  • int =5


5566490

    • byte short int long float double char boolean

    • if else switch case default do while for break continue

    • private public protected final static abstract synchronized volatile

    • try catch finally throw throws


5566490

    • new extends implements class instanceof this super

    • false true null

    • return void

    • package import


5566490

    • //

    • /*

    • */


5566490

  • [] <> <> [=<>][,<>[=<>].]

    • int i

    • int j=5k=4;


5566490

  • { }


5566490

  • 23423.4atruefalsehello world

  • final

  • final int MAX=100;

  • final int MAX_LOOP=5;


5566490

(byte,short,int,long)

(float,double)

(char)

boolean

(class)

(interface)

Java


5566490

  • Java


5566490

  • Java

    • boolean b=false;


Boolean

boolean

  • truefalse

  • boolean x;

  • boolean x=true;


5566490

  • 16Unicode

  • char c,c1=a

  • Unicode\u4e2d


5566490

char

  • JavaUnicode

  • ASCIIUnicode128

  • Unicode\n

  • Unicodeint0~65535Unicodechar


5566490

public class Example2_1

{ public static void main (String args[ ])

{ char chinaWord='',japanWord='';

int p1=36328,p2=38358;

System.out.println("\'\'unicode:"+(int)chinaWord);

System.out.println("\'\'unicode:"+(int)japanWord);

System.out.println("unicode36328:"+(char)p1);

System.out.println("unicode38358:"+(char)p2);

}

}


5566490

  • Java

    • 0~90124-100

    • 00~70134

    • 0x0X0~9A~Fa~fa~fA-F10~150x23FE9214


5566490

longLl3Llongint


5566490

doubleFffloat3.45double3.45Ffloat


5566490

  • byte-short-int-long-float-double(

  • byteshortintlong


5566490

public class Example

{ public static void main (String args[ ])

{ int c=2200;

long d=8000;

float f;

double g=123456789.123456789;

c=(int)d;

f=(float)g; //.

System.out.print("c= "+c);

System.out.println(" d= "+d);

System.out.println("f= "+f);

System.out.println("g= "+g);

}

}


5566490

    • ----------------------------------------------- --->

    • byteshortchar---> int--> long--> float--> double

  • byteshortcharint

    • byte b1=5

    • short s1=6

    • short s2

    • s2=b1+s1;


5566490

    • int i65

    • char c;

    • c=(char)i; // intchar


5566490


5566490

  • ++-- ++--


5566490

  • Java,"%",52.3%10=2.3

  • Java"+",,"ab"+"efd""abefd"

  • "+",,.: String s; s="s:"+4*5; //s="s:20"

  • byteshortcharint


5566490

  • j=i+20;


5566490

  • (boolean_expr)? true_statement:false_statement

  • result=sum==0?100:2*num;


5566490

  • Java

  • 1

    • 00000000 00000000 00000000 000000014

  • -1

    • 11111111 11111111 11111111 11111111 4


5566490


5566490

  • ~ ,

  • &,|,^boolean

  • ">>",">>>".

  • ,a&b,abyte,bint,a24,a,0,a,1


5566490

&


5566490

class Example

{ public static void main(String args[])

{ char a1='',a2='',a3='',a4='';

char secret='8';

a1=(char)(a1^secret);

a2=(char)(a2^secret);

a3=(char)(a3^secret);

a4=(char)(a4^secret);

System.out.println(":"+a1+a2+a3+a4);

a1=(char)(a1^secret);

a2=(char)(a2^secret);

a3=(char)(a3^secret);

a4=(char)(a4^secret);

System.out.println(":"+a1+a2+a3+a4);

}

}


5566490

  • 5<<32

  • -1>>>1


5566490


5566490

class Example

{ public static void main(String args[])

{ int x,y=10;

if(((x=0)==0)||((y=20)==20))

{ System.out.println("y:"+y);

}

int a,b=10;

if(((a=0)==0)|((b=20)==20))

{ System.out.println("b:"+b);

}

}

}


5566490


5566490


5566490

  • .,[],()


5566490

    • Object

    • Object


5566490

()

    • public final length length


5566490


5566490

  • Declaration


5566490

()

Type[ ] arrayName;

int[] intArray;

String[] stringArray;

Type arrayName[ ];

int intArray[];

String stringArray[];


5566490

  • new


5566490

()

arryName=new Type[componets number];

  • int[] ai; ai=new int[10];

    String[] s; s=new String[3];

  • int ai[]=new int[10];

  • String[] s1=new String[3], s2=new String[8];


5566490

  • inta[]={22, 33, 44, 55};

    • 0

    • booleanfalse;

    • null


5566490

  • arrayName[index]

  • int , short, byte, char.

  • .

  • arryName.length

  • length 1ArrayIndexOutOfBoundsException


5566490

()

int[] data = new int[10];

  • data[ -1 ]

  • data[ 10 ]

  • data[ 1.5 ]

  • data[ 0 ]

  • data[ 9 ]


5566490

()

int values[] = new int[7];

int index;

index = 0;

values[ index ] = 71;

index = 5;

values[ index ] = 23;

index = 3;

values[ 2+2 ] = values[ index-3 ];


5566490

()

public class MyArray {

public static void main(String[] args){

int myArray[]; //

myArray=new int[10]; //

System.out.println("Index\t\tValue");

for(int i=0; i<myArray.length;i++)

System.out.println(i+"\t\t"+myArray[i]);

//0

//myArray[10]=100; //

}

}


5566490

()

  • public class Arrays

    { public static void main(String[] args)

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

    int[] a2;

    a2 = a1;

    for(int i = 0; i < a2.length; i++) a2[i]++;

    for(int i = 0; i < a1.length; i++)

    System.out.println( "a1[" + i + "] = " + a1[i]);

    }

    }


5566490

()

a1[0] = 2

a1[1] = 3

a1[2] = 4

a1[3] = 5

a1[4] = 6


5566490

()

  • String[] strArray;

    strArray = new String[8] ;

    strArray[0]= "Hello" ;


5566490

()

  • public class ArrayOfStringsDemo

    { public static void main(String[] args)

    { String[] anArray =

    { "String One", "String Two", "String Three"};

    for (int i = 0; i < anArray.length; i++)

    { System.out.println(anArray[i].toLowerCase());

    }

    }

    }

string one

string two

string three


5566490

source

()

  • public static void arraycopy(Objectsource , intsrcIndex , Objectdest , intdestIndex , intlength )


5566490

()

public class ArrayCopyDemo

{ public static void main(String[] args)

{ char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',

'i', 'n', 'a', 't', 'e', 'd'};

char[] copyTo = new char[7];

System.arraycopy(copyFrom, 2, copyTo, 0, 7);

System.out.println(new String(copyTo));

}

}


5566490

int[][] gradeTable;

gradeTable[ 0 ][ 1 ]42

gradeTable[ 3 ][ 4 ]93

gradeTable[ 6 ][ 2 ]78


5566490

()

    • int[ ][ ] myArray ;

      • myArray 2null

    • int[ ][ ] myArray = new int[3][5] ;

      • myArray

    • int[ ][ ] myArray = { {8,1,2,2,9}, {1,9,4,0,3}, {0,3,0,0,7} };


5566490

()

  • class UnevenExample2

    { public static void main( String[ ] arg )

    { int[ ][ ] uneven =

    { { 1, 9, 4 },

    { 0, 2},

    { 0, 1, 2, 3, 4 } };

    System.out.println("Length is: " + uneven.length );

    }

    }

Length is: 3


5566490

()

  • class UnevenExample3

    {

    public static void main( String[] arg )

    {

    // 2

    int[ ][ ] uneven =

    { { 1, 9, 4 },

    { 0, 2},

    { 0, 1, 2, 3, 4 } };


5566490

()

// ()

System.out.println("Length of array is: " + uneven.length );

//

System.out.println("Length of row[0] is: " + uneven[0].length );

System.out.println("Length of row[1] is: " + uneven[1].length );

System.out.println("Length of row[2] is: " + uneven[2].length );

}

}

Length of array is: 3

Length of row[0] is: 3

Length of row[1] is: 2

Length of row[2] is: 5


5566490

int[ ][ ] myArray;

myArray = new int[3][ ] ;

myArray[0] = new int[3];

int[ ] x = {0, 2};

int[ ] y = {0, 1, 2, 3, 4} ;

myArray[1] = x ;

myArray[2] = y ;

()


5566490

  • int a[ ]

  • int[ ] a

  • a

    • int a[ ]={01234}


5566490

new

  • <>= new <>[ <> ]

  • a=new int[5];

  • int a[ ] =new int[5]

  • length


5566490


5566490

0

a[0]

0

a[0]

1

a[1]

0

a[1]

a

null

a

0x0345o

a

0x4345o

2

a[2]

0

a[2]

3

a[3]

0

a[3]

4

a[4]

0

a[4]

aint a[ ]

(b) int a[ ]={0,1,2,3,4}

(c) int a[ ]

a=new int[5];


5566490

    • int two[][]

    • int[][] two

    • int two[][]={{012}{345}}


5566490

new

  • int two[ ][ ]=new int[2][3];

  • int two[ ][ ]

  • two=new int[2 ][3 ]

  • int two[ ][ ]

    • two =new int[2][ ];

    • two[0]=new int[2];

    • two[1]=new int[3];


  • Login