Java.p1.pdf

download Java.p1.pdf

of 15

Transcript of Java.p1.pdf

  • 7/23/2019 Java.p1.pdf

    1/15

    I

    J

    L ,

    L

    L

    P

    ,

    .

    C

    (W, L, )

    S

    W

    P

    U

    .A ' J,

    T

    .

    L J

    C

    C

    ..

    ,

    J, I ( :

    J :

    (, , )

    ,

    (

    C++).

    '

    .

    C/C++ W,

    . Q

    .

    L.

    L

    L. D

    .

    ,

    :

    I

    BYTECODE

    C

    E

    1

    1995.

    . E W).

    '

    ,

    .

    C

  • 7/23/2019 Java.p1.pdf

    2/15

    I .. 2

    I J , '

    , .

    Q , , .

    E , .

    P , . Q

    V M,

    .

    A ' , ' .

    P J (

    ' ).

    L' J , ,

    .

    L :

    ..: ( )

    ..:

    ..: (, , , )

    ..:

    ..: ( , , )

    E J: (

    ), S M,

    J.

    I JDK : ' . C

    W, ' J, .

    P J . G

    :

    ( B W)

    J ( JDK)

    W

    API (A P I),

    JDK.

    S JDK, , , '

    .

    P ' ,

    PATH V ' ( :://../////%20..).

    P J ( ),

    '

    . U TP, :

    ://..////TP.I.542.

    P T :

    ://../////%20.

  • 7/23/2019 Java.p1.pdf

    3/15

    I .. 3

    U' . T ,

    , . L' ' J .

    U J, , :

    class NomeClasse // NomeClasse deve coincidere con il nome del file memorizzato sul disco

    {

    public static void main(String args[])

    {

    // dichiarazioni di variabili

    // istruzioni

    }

    }

    1

    class Saluto

    { //INIZIO class

    public static void main(String args[])

    { //INIZIO main

    System.out.print("Buongiorno a tutti,"); //Stampa e non va a capo

    System.out.println("iniziamo a programmare in Java"); //Stampa e va capo

    System.out.println("");System.out.println("Buon lavoro !!!");

    } //FINE main

    } //FINE class

    I , :

    ;

    ;

    D , , . I

    ,, '.

    J . Q B, BASE .

    I J .

    P .

    L .

    P ////.

    P //** **//.

    P J :

    1. J (B , W, )

    2. :

    ( class)

    ..

    3.

    , P DOS : javacnomeClasse.java

    S

    nomeClasse.class ( ).

    P P DOS

    : javanome Classe

    I ' J

    () , .

    .

  • 7/23/2019 Java.p1.pdf

    4/15

    I .. 4

    G , .

    U . I .

    P .

    L :

    ,

    ,

    ' ( , R, N, )

    G .

    II ' .

    TT

    8 128 , 127

    16 32768 , 32767

    II 32 2 147 483 648 , 2 147 483 647

    64 263

    , 263

    1

    TT

    32 , ( 6 7 )

    64 , ( 14 15 )

  • 7/23/2019 Java.p1.pdf

    5/15

    I .. 5

    L .

    G : , .

    L :

    DD

    S E

    tipo nomeVariabile

    int base

    byte numeroLotto

    double altezza=1,83

    U , ,

    . I . A'

    .

    N , ' .

    P .

    U , , ' .

    P .

    DD

    S E

    final tipo nome = valore final double PI_GRECO = 3.14

    II

    I .

    I , , , .

    ==55;;

    ==33;;

    ==(()) //

    ==33..1144;;

    ____==(())

  • 7/23/2019 Java.p1.pdf

    6/15

    I .. 6

    L ' .

    P ' ', .

    A , J,

    P J.

    import java.io.*;

    class RettangoloBufferedReader

    {

    public static void main(String[] args) throws IOException

    {

    BufferedReader stdin = new BufferedReader

    (new InputStreamReader(System.in));

    int base, altezza, area;

    System.out.print("Base = ");

    System.out.flush();

    base = Integer.parseInt(stdin.readLine());

    System.out.print ("Altezza = ");

    System.out.flush();

    altezza = Integer.parseInt(stdin.readLine());

    area = base*altezza;

    System.out.println("Area = "+area);

    }

    }

    UU,,UUNNIICCAALL,,::

    import system.IO;

    public class AreaRettangolo

    {

    public static void main(String[] args)

    {

    int base, altezza, area;

    System.out.print("Base = ");

    base=IO.in.readInt();

    System.out.print ("Altezza = ");

    altezza = IO.in.readInt();

    area = base*altezza;

    System.out.print("Area = "+area);

    }

    }

    INIZIO

    L

    S

    FINE

    L

  • 7/23/2019 Java.p1.pdf

    7/15

    I .. 7

    PP

    NNVV....(()) IINNPPUUTT = IO..I ( )

    NNVV....(()) IINNPPUUTT = IO..L ( )

    NNVV....(()) IINNPPUUTT = IO..B ( )

    NNVV....(()) IINNPPUUTT = IO..S ( )

    NNVV....(()) IINNPPUUTT = IO..D ( )

    NNVV....(()) IINNPPUUTT = IO..D ( )

    NNVV....(()) IINNPPUUTT SSNN= IO..B ( ) SSNN

    NNVV....(()) IINNPPUUTT CC= IO..C ( )

    NNVV....(()) IINNPPUUTT = IO..S ( )

    OO

    ==== U ==3

    !!== D != 3

    == M >= 3

    %% R 23 % 5 3

    OO

    &&&& AND ( > 3) && ( < 5) ( >3) ( < 5)

    OR ( < 3) ( > 5) ( < 3) ( > 5)

    !! NOT != 3

    OO//

    ++++ ++++ ==++11 = 5; ++

    ---- ---- ==--11 = 5; ----

    ++== ++== ==++ = 5; += 2

    --== --== ==-- = 5; --= 2

    **== **== ==** = 5; *= 2

    //== //== ==// = 6; /= 3

    %%== %%== ==%% = 5; %= 3

  • 7/23/2019 Java.p1.pdf

    8/15

    I .. 8

    CCMM

    ....MM;;

    (()) S M.(30)

    (()) C M.(60)

    (()) T M.(45)

    (()) A M.(0.5)

    (()) A M.(0.5)

    (()) A M.(0.5)

    (()) E M.(2)

    (()) L M.(5)

    ((,,)) P M. (2, 3)

    (()) A M. (3,6)

    (()) V M. (3)

    (()) N [0..1[ M.()

    ((,,)) M M.(3,5)

    ((,,)) M M.(3,5)

    CCSS

    S1.(S2) boolean x ;

    x = S1.equals(S2);

    RVERO

    Stringa1 = Stringa2S1.TT(S2) S1.compareTo(S2>0)

    (()) int x;

    x = Stringa1.length();

    R

    Stringa1

    AA(()) C String Stringa1 = "Ciao";

    char x = Stringa1.charAt(2);

    R

    , a( 2)

    IIOO(())

    String Stringa1 = "Pippo"

    int x = Stringa1.indexOf("po")

    L 3.

    S

    -1

    WW(())

    String Stringa1 = "Pippo";

    Boolean

    x = Stringa1.startsWith("Pi");

    RVERO

    S1 Pi

    WW(())

    String Stringa1 = "Pippo";

    Boolean

    x = Stringa1.startsWith("po");

    RVERO S1 po

    (())

    String Stringa1 = "Martina";

    String

    x = Stringa1.substring(3);

    R tina

    S1.(S2)

    OS1 + S2

    String S1="Ciao";

    String S2="Mondo";

    String S3=S1.concat(S2);

    (String S3 = S1 + S2;)

    R S3 = Ciao Mondo

    s1.UUCC()

    String S1="Ciao";

    S2=s1.toUpperCase();R S2 = CIAO

    s1.LLCC()

    String S1="CIAO";

    S2=s1.toLowerCase();R S2 = ciao

    IIOO....LL(()) R S1=IO.in.readLine()

    NOTA

    S.. (+R+) NO S.. (++R+) SI

  • 7/23/2019 Java.p1.pdf

    9/15

    I .. 9

    I .

    L . P

    .

    S A.

    S B.

    C

    I A

    I B

    (C = V) I A;

    I B; (C = V) I A;

    II

  • 7/23/2019 Java.p1.pdf

    10/15

    I .. 10

    D , .

    (I: =3 ; =5)

    1 INIZIO 1 INIZIO

    2 L 2 3

    3 L 3 54 >

    S

    S

    4 F

    5 5

    6 6 55

    7 FINE 7 FINE

    import system.IO;

    class max

    {

    public static void main (String args[])

    {

    int a, b;

    System.out.print("Introduci il primo numero: ");

    a = IO.in.readInt();

    System.out.print("Introduci il secondo numero: ");

    b = IO.in.readInt();

    if (a > b)

    System.out.println("Il MAX e' " +a);

    else

    System.out.println("Il MAX e' " +b);

    }

    }

    FINE

    INIZIO

    L

    L

    SS

  • 7/23/2019 Java.p1.pdf

    11/15

    I .. 11

    I . O

    , .

    I .

    S

    V 1: I A

    V 2: I B

    V 3: I C

    . . . . .

    I X

    ( )

    : ;

    : ;

    : ;

    ...

    : ;

    I , .

    import system.IO;

    class giornoSettimanale

    {

    public static void main (String args[])

    {

    int numeroGiorno;

    String giorno;

    System.out.print("Quale giorno (in numero) della settimana e' oggi ? ");

    numeroGiorno = IO.in.readInt();

    switch ( numeroGiorno )

    {

    case 1: giorno = "Lunedi'"; break;

    case 2: giorno = "Martedi'"; break;

    case 3: giorno = "Mercoledi'"; break;

    case 4: giorno = "Giovedi'"; break;

    case 5: giorno = "Venerdi'"; break;

    case 6: giorno = "Sabato"; break;

    case 7: giorno = "Domenica"; break;

    default: giorno = null; // in tutti gli altri casi

    }

    System.out.println("Oggi e' "+giorno);}

    }

    I I I I

  • 7/23/2019 Java.p1.pdf

    12/15

    I .. 12

    I , , .

    L ().

    I .

    L .

    L .

    L

    .

    R 10 A (IItteerraazziioonnee ddeeffiinniittaa))

    B (IItteerraazziioonnee inddeeffiinniittaa))

    L ( )

    .

    L ( )

    .

    M C = V

    I

    R I

    R I

    N

    (C = V)

    I

    I

    (C = F)

    (=1; < NI; ++)

    I

    I

    1,

  • 7/23/2019 Java.p1.pdf

    13/15

    I .. 13

    1

    C , G

    .

    (I N=5)

    <

    1 INIZIO 3 1

    2 L 4 03 A 5 V

    4 A 7 0+1=1

    5

    A

    I

    8 2

    6 5 V

    7 7 1+2=3

    8 8 3

    9 5 V

    10 S 7 3+3=6

    11 FINE 8 4

    5 V

    7 6+4=10

    8 55 V

    7 10+5=15

    8 6

    5 F

    10 1155

    11 FINE

    import system.IO;

    class sommaNumeri_While

    {

    public static void main (String [] args)

    {

    int contatore, somma, n;

    IO.out.println(" SOMMA DEI PRIMI N NUMERI NATURALI");

    IO.out.print("Introduci un numero naturale: ");

    n = IO.in.readInt();

    somma = 0;

    contatore = 1;

    while (contatore

  • 7/23/2019 Java.p1.pdf

    14/15

    I .. 14

    2

    C , G

    .

    (I N=5)

    <

    1 INIZIO 1 INIZIO

    2 L 23 A 3 0

    4 A 4 0

    5

    A

    I

    7 0+0=0

    6 8 1

    7 10 V

    8 7 1+2=3

    9 8 2

    10 10 V

    11 S 7 3+3=6

    12 FINE 8 3

    10 V

    7 6+4=108 4

    10 V

    7 10+5=15

    8 5

    10 F

    11 1155

    12 FINE

    import system.IO;

    class sommaNumeri_Do

    {

    public static void main (String [] args)

    {

    int contatore, somma, n;

    IO.out.println(" SOMMA DEI PRIMI N NUMERI NATURALI");

    IO.out.print("Introduci un numero naturale: ");

    n = IO.in.readInt();

    contatore=0;

    somma = 0;

    do

    {

    somma = somma + contatore;

    contatore++;

    }

    while (contatore

  • 7/23/2019 Java.p1.pdf

    15/15

    3

    C , G

    .

    (N=5)

    1 INIZIO 3 0

    2 L 4 13 A 6 0+1=1

    4 R

    A

    4 2

    5 6 1+2=3

    6 4 3

    7 6 3+3=6

    8 4 4

    9 S 6 6+4=10

    10 FINE 4 5

    6 10+5=15

    9 1155

    10 FINE

    import system.IO;

    class sommaNumeri_For

    {

    public static void main (String [] args)

    {int contatore, somma, n;

    IO.out.println(" SOMMA DEI PRIMI N NUMERI NATURALI");

    IO.out.print("Introduci un numero naturale: ");

    n = IO.in.readInt();

    somma = 0;

    for (contatore=1; contatore