bai thuc hanh java

/**

* @(#)FirstDialog.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class FirstDialog {

public static void main(String[] args){

JOptionPane.showMessageDialog(null, "xin chao cac ban !");

System.exit(0);

}

}

/**

* @(#)GPTBac1.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class GPTBac1 {

public static void main (String[] args)

{

float a,b;

a=Integer.parseInt(JOptionPane.showInputDialog(null,"Hay nhap so thu nhat","Hay nhap so thu 1: ",JOptionPane.INFORMATION_MESSAGE));

b=Integer.parseInt( JOptionPane.showInputDialog(null,"Hay nhap so thu hai","Hay nhap so thu 2:",JOptionPane.INFORMATION_MESSAGE));

if(a==0)

{ if(b==0)

System.out.print("phuong trinh vo so nghiem");

else

System.out.print("phuong trinh vo nghiem");

}

else

System.out.print("phuong trinh co nghiem x= " +(-b/a));

}

}

/**

* @(#)GPTBac2.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import java.math.*;

import javax.swing.JOptionPane;

public class GPTBac2 {

public static void main (String[] args)

{

float a,b,c,d;

a=Integer.parseInt(JOptionPane.showInputDialog(null,"Hay nhap so thu nhat","Hay nhap so thu 1: ",JOptionPane.INFORMATION_MESSAGE));

b=Integer.parseInt( JOptionPane.showInputDialog(null,"Hay nhap so thu hai","Hay nhap so thu 2:",JOptionPane.INFORMATION_MESSAGE));

c=Integer.parseInt(JOptionPane.showInputDialog(null,"Hay nhap so thu nhat","Hay nhap so thu 1: ",JOptionPane.INFORMATION_MESSAGE));

if(a==0)

{ if(b==0)

{if(c==0)

System.out.print("phuong trinh vo so nghiem");

else

System.out.print("Phuong trinh vo nghiem");

}

else

System.out.print("Phuong trinh co mot nghiem x= "+(-c/a));

}

else

{ d=(b*b-4*a*c) ;

if(d<0)

System.out.print("phuong trinh vo nghiem");

if(d==0)

System.out.print("Phuong trinh co nghiem kep: "+(-b/a));

if(d>0)

{

System.out.println("Phuong trinh hai nghiem x1:");

System.out.println(((-b)+Math.sqrt(d))/(2*a));

System.out.println("Phuong trinh hai nghiem x2:");

System.out.print(((-b)-Math.sqrt(d))/(2*a));

}

}

}

}

/**

* @(#)HellloWorld.java

*

*

* @author

* @version 1.00 2009/11/18

*/

public class HellloWorld {

public static void main(String args[]) {

System.out.println("xin chao

cac ban!");

System.out.println("Hello \t world");

}// end method main

}

/**

* @(#)HelloNameDialog.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class HelloNameDialog {

public static void main (String[] args) {

String result;

result=JOptionPane.showInputDialog("Hay nhap ten ban:");

JOptionPane.showMessageDialog(null,"Xin Chao" + result + "!");

System.exit(0);

}

}

/**

* @(#)HienthiHaiSo.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class HienthiHaiSo {

public static void main(String[] args) {

String strSo1, strSo2;

String strHienThi="Ban vua nhap ";

strSo1=JOptionPane.showInputDialog(null,

"Hay nhap so thu nhat:",JOptionPane.INFORMATION_MESSAGE);

strHienThi+= strSo1+" va ";

strSo2= JOptionPane.showInputDialog(null,

"Hay nhap so thu hai:",JOptionPane.INFORMATION_MESSAGE);

strHienThi+=strSo2;

JOptionPane.showMessageDialog( null,strHienThi,

"Hien thi hai so",JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}

/**

* @(#)InTamGiac.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import java.util.*;

public class InTamGiac {

public static void main(String[] args) {

int i,j;

for(i=1;i<6;i++)

{for(j=1;j<=6+i-1;j++)

if(j>=6-i+1)

System.out.print("*");

else

System.out.print(" ");

System.out.print("

");

}

}

}

/**

* @(#)LuaChon.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class LuaChon {

public static void main(String[] agrs) {

int iLuaChon;

String strLuaChon;

iLuaChon=JOptionPane.showConfirmDialog(null,"Ban co muon chuyen sang hang nhat khong?");

if(iLuaChon==JOptionPane.YES_OPTION)

strLuaChon="co";

else

strLuaChon="khong";

JOptionPane.showMessageDialog(null,"Ban da chon "+ strLuaChon);

System.exit(0);

}

}

/**

* @(#)SuaBaiLuaChon.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class SuaBaiLuaChon {

public static void main( String[] args){

int iLuaChon;

String strLuaChon;

iLuaChon=JOptionPane.showConfirmDialog(null,"Co loi xay ra. Ban co muon tiep tuc?","Loi",JOptionPane.YES_NO_OPTION,JOptionPane.ERROR_MESSAGE);

if(iLuaChon==JOptionPane.YES_OPTION)

strLuaChon="co";

else

strLuaChon="khong";

JOptionPane.showMessageDialog(null,"Ban da chon "+ strLuaChon);

System.exit(0);

}

}

/**

* @(#)TongHaiSo.java

*

*

* @author

* @version 1.00 2009/11/18

*/

import javax.swing.JOptionPane;

public class TongHaiSo {

public static void main(String[] args) {

int a, b, c;

a=Integer.parseInt(JOptionPane.showInputDialog(null,"Hay nhap so thu nhat","Hay nhap so thu 1: ",JOptionPane.INFORMATION_MESSAGE));

b=Integer.parseInt( JOptionPane.showInputDialog(null,"Hay nhap so thu hai","Hay nhap so thu 2:",JOptionPane.INFORMATION_MESSAGE));

c=a+b;

JOptionPane.showMessageDialog( null,"Tong hai so "+a+" va "+b+" la: "+c ,"Tong thi hai so",JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}

Bạn đang đọc truyện trên: AzTruyen.Top