Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

TH BAI THUC HANH 1

/*PTB1

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package bai1;

/**

*

* @author Tran Van Thai

*/

import javax.swing.JOptionPane;

public class PTBac1 {

public static void main(String args[]){

boolean check1,check2;

double a=0,b=0;

//kiem tra nhap a

do

{

String stra=JOptionPane.showInputDialog("Nhap he so a:",JOptionPane.ERROR_MESSAGE);

try

{

a=Double.parseDouble(stra);

check1=true;

}

catch(Exception e)

{

check1=false;

}

} while(check1==false);

//kiem tra nhap b

do

{

String strb=JOptionPane.showInputDialog("Nhap he so b:",JOptionPane.ERROR_MESSAGE);

try

{

b=Double.parseDouble(strb);

check2=true;

}

catch(Exception e)

{

check2=false;

}

} while(check2==false);

JOptionPane.showMessageDialog(null,"Phuong trinh vua nhap la:"+a+"x+"+b);

if(a==0)

if(b==0)

JOptionPane.showMessageDialog(null,"Phuong trinh co vo so nghiem!");

else

JOptionPane.showMessageDialog(null,"Phuong trinh vo nghiem!");

else

JOptionPane.showMessageDialog(null,"Phuong trinh co nghiem x="+(-b/a));

}

}

/*PTB2

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package bai1;

/**

*

* @author Tran Van Thai

*/

import javax.swing.JOptionPane;

public class PTBac2 {

public static void main(String argsp[]){

boolean check1,check2,check3;

double a=0,b=0,c=0;

do

{

String stra=JOptionPane.showInputDialog("Nhap he so a:");

try

{

a=Double.parseDouble(stra);

check1=true;

}

catch(Exception e)

{

check1=false;

}

} while(check1==false);

do

{

String strb=JOptionPane.showInputDialog("Nhap he so b:");

try

{

b=Double.parseDouble(strb);

check2=true;

}

catch(Exception e)

{

check2=false;

}

} while(check2==false);

do

{

String strc=JOptionPane.showInputDialog("Nhap he so c:");

try

{

c=Double.parseDouble(strc);

check3=true;

}

catch(Exception e)

{

check3=false;

}

} while(check3==false);

JOptionPane.showMessageDialog(null,"Phuong trinh vua nhap la:"+a+"x^2+"+b+"x_"+c);

if(a==0)

if(b==0)

if(c==0)

JOptionPane.showMessageDialog(null,"Phuong trinh co vo so nghiem!");

else

JOptionPane.showMessageDialog(null,"Phuong trinh vo nghiem!");

else

JOptionPane.showMessageDialog(null,"Phuong trinh co nghiem duy nhat x="+(-c/b));

else

{

double delta=Math.pow(b, 2)-4*a*c;

if(delta<0)

JOptionPane.showMessageDialog(null,"Phuong trinh vo nghiem!");

else if(delta==0)

JOptionPane.showMessageDialog(null,"Phuong trinh co nghiem kep:x1=x2="+(-b/(2*a)));

else

{

JOptionPane.showMessageDialog(null, "Phuong trinh co 2 nghiem phan biet:");

JOptionPane.showMessageDialog(null,"x1="+((-b+Math.sqrt(delta))/(2*a)));

JOptionPane.showMessageDialog(null,"x1="+((-b-Math.sqrt(delta))/(2*a)));

}

}

}

}

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package bai2_TONG SO THUC;

/**

*

* @author Tran Van Thai

*/

import javax.swing.JOptionPane;

public class Bai2 {

public static void main(String args[]){

double tong=0;

int check;

boolean ktra;

do

{

do

{

try

{

tong+=Double.parseDouble(JOptionPane.showInputDialog("Nhap so thuc"));

ktra=true;

}

catch(Exception e)

{

ktra=false;

}

}while(ktra==false);

check=JOptionPane.showConfirmDialog(null, "ban co muon nhap tiep ko?","Xac nhan tiep",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);

} while(check==JOptionPane.YES_OPTION);

JOptionPane.showMessageDialog(null, "Tong la:"+tong);

}

}

/* NGAY THANG 1

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package bai3;

/**

*

* @author VY

*/

import javax.swing.JOptionPane;

public class NgayThang {

public static void main(String[] args)

{

String strMonth="";

String strYear="";

int i;

int iMonth;

int iYear;

String strResult="";

//check ngay thang co nhap dung hay ko

do

{

String strInput=JOptionPane.showInputDialog("Nhap theo dinh dang mm/yyyy:");

for (i=0;i<strInput.length();i++)

{

if(strInput.charAt(i)=='/')

{

strMonth=strInput.substring(0,i);

strYear=strInput.substring(i+1, strInput.length()-i);

}

}

iMonth=Integer.parseInt(strMonth);

iYear=Integer.parseInt(strYear);

} while(iMonth<1||iMonth>12||iYear<1);

if(iMonth%2==1&&iMonth<8)

strResult="thang nay co 31 ngay";

if(iMonth%2==0&&iMonth<8)

strResult="thang nay co 30 ngay";

if(iMonth==2)

strResult="thang nay co 28 ngay";

if(iMonth>=8&&iMonth%2==0)

strResult="thang nay co 31 ngay";

if(iMonth>=8&&iMonth%2==1)

strResult="thang nay co 30 ngay";

if(iYear%4==0&&iMonth==2)

strResult="thang nay co 29 ngay";

//print Result thoi :))

JOptionPane.showMessageDialog(null,strResult);

}

}

/*NGAY THANG 2

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package bai3;

/**

*

* @author VY

*/

import javax.swing.JOptionPane;

public class NgayThang2 {

public static void main(String args[]){

boolean check1,check2;

int month=0,year=0;

String strResult="";

do

{

String strMonth=JOptionPane.showInputDialog("Nhap thang");

try

{

month=Integer.parseInt(strMonth);

check1=true;

}

catch(Exception e)

{

check1=false;

}

} while((check1==false)||(month<1)||(month>12));

do

{

String strYear=JOptionPane.showInputDialog("Nhap nam");

try

{

year=Integer.parseInt(strYear);

check2=true;

}

catch(Exception e)

{

check2=false;

}

} while((check2==false)||(year<1));

if(month%2==1&&month<8)

strResult="thang nay co 31 ngay";

if(month%2==0&&month<8)

strResult="thang nay co 30 ngay";

if(month==2)

strResult="thang nay co 28 ngay";

if(month>=8&&month%2==0)

strResult="thang nay co 31 ngay";

if(month>=8&&month%2==1)

strResult="thang nay co 30 ngay";

if(year%4==0&&month==2)

strResult="thang nay co 29 ngay";

JOptionPane.showMessageDialog(null,strResult);

}

}

Bạn đang đọc truyện trên: Truyen247.Pro