Toan_BT1

download Toan_BT1

of 7

Transcript of Toan_BT1

  • 8/8/2019 Toan_BT1

    1/7

    Bi tp 1: c ti liu lp trnh hng i tng v vit chy 10 v d trong

    sch (coppy hnh chy vo file)

    Bi lm

    V d 1

    CODE Hnh chy/** To change this template, choose Tools |

    Templates* and open the template in the editor.*/

    package dinhquangtoan_bai1;

    /**

    ** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

    arguments*/

    public static void main(String[] args) {// TODO code application logic here

    System.out.println("Hello World");}

    }

    V d 2

    CODE Hnh chy/** To change this template, choose Tools |

    Templates* and open the template in the editor.*/

    package dinhquangtoan _bai2;

    /**** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

  • 8/8/2019 Toan_BT1

    2/7

    arguments*/

    public static void main(String[] args) {// TODO code application logic hereSystem.out.println("This is what the

    main method received");System.out.println(args[0]);

    System.out.println(args[1]);System.out.println(args[2]);}

    }

    V d 3

    CODE Hnh chy/*

    * To change this template, choose Tools| Templates* and open the template in the editor.*/

    package dinhquangtoan _bai3;

    /**** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

    arguments*/

    public static void main(String[] args){

    // TODO code application logichere

    int num=10;

    if(num%5==0)System.out.println(num + "is

    divisable for 5!");else

    System.out.println(num + "isindivisable for 5!");

    }

    }

  • 8/8/2019 Toan_BT1

    3/7

    V d 4

    CODE Hnh chy/** To change this template, choose Tools |

    Templates* and open the template in the editor.*/

    package dinhquangtoan_bai4_switchdemo;

    /**** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

    arguments*/

    public static void main(String[] args) {// TODO code application logic hereint day = 2;switch(day)

    {case 0 :

    System.out.println("Sunday");break;

    case 1 :System.out.println("Monday");break;case 2 :

    System.out.println("Tuesday");break;case 3 :

    System.out.println("Wednesday");break;case 4 :

    System.out.println("Thursday");

    break;case 5 :System.out.println("Friday");

    break;case 6 :

    System.out.println("Satuday");break;default:

    System.out.println("Invalidday of week");

    }

    }

    }

  • 8/8/2019 Toan_BT1

    4/7

    V d 5

    CODE Hnh chy/** To change this template, choose Tools |

    Templates* and open the template in the editor.

    */

    package dinhquangtoan _bai5_whiledemo;

    /**** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

    arguments*/

    public static void main(String[] args) {// TODO code application logic hereint a = 5, sum = 1;while(a>=1){

    sum+=a;a--;

    }System.out.println("the sum is " +sum);

    }

    }

  • 8/8/2019 Toan_BT1

    5/7

    V d 6

    CODE Hnh chy/** To change this template, choose Tools |

    Templates* and open the template in the editor.

    */

    packagedinhquangtoan_bai6_dowhiledemo;

    /**** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

    arguments*/

    public static void main(String[] args) {// TODO code application logic hereint a=1, sum=0;do{

    sum+=a;

    a++;}while(a

  • 8/8/2019 Toan_BT1

    6/7

    V d 7

    CODE Hnh chy/** To change this template, choose Tools

    | Templates* and open the template in the editor.

    */

    package dinhquangtoan _bai7_fordemo;

    /**** @author dlvhnghdls*/

    public class Main {

    /*** @param args the command line

    arguments*/

    public static void main(String[] args) {// TODO code application logic hereint sum=0;for(int i=1; i=2)

    { x=Integer.parseInt(args[0]);y=Integer.parseInt(args[1]);

  • 8/8/2019 Toan_BT1

    7/7

    }if(x>0 && y>0){

    int chuvi=2*(x+y);System.out.println("Chu vi la" +

    chuvi);int dientich=x*y;

    System.out.println("Dien tich la"+ dientich);}

    elseSystem.out.println("Cac tham so

    khong dung");}

    }