DAICATAI Thái Sư
Tổng số bài gửi : 31 Age : 36 Đến từ : Lòng Đất Registration date : 08/04/2008
| Tiêu đề: Tui khai trương một số bài trước nha Sat Sep 13, 2008 10:52 pm | |
| Chương trình đánh năm và in ra tên năm ...ví dụ năm 1968 ~~> in ra đây là năm mậu thân . - Code:
-
class dieukien { public static void main (String[] arg) { int n=Integer.parseInt(arg[0]); System.out.println("CHUONG TRINH DANH NAM CHO BIET TEN NAM DO THEO LICH AM"); System.out.println("Neu day la nam"+" "+n +" "+"thi theo Am Lich day la nam :"); if(n%10 ==4) System.out.print("Giap"+" "); if(n%10 ==5) System.out.print("At"+" "); if(n%10 ==6) System.out.print("Binh"+" "); if(n%10 ==7) System.out.print("Dinh"+" "); if(n%10 ==8) System.out.print("Mau"+" "); if(n%10 ==9) System.out.print("Ky"+" "); if(n%10 ==0) System.out.print("Canh"+" "); if(n%10 ==1) System.out.print("Tan"+" "); if(n%10 ==2) System.out.print("Nham"+" "); if(n%10 ==3) System.out.print("Quy"+" "); if(n%12==4) System.out.print("Ty"); if(n%12==5) System.out.print("Suu"); if(n%12==6) System.out.print("Dan"); if(n%12==7) System.out.print("Meo"); if(n%12==8) System.out.print("Thin"); if(n%12==9) System.out.print("Ti"); if(n%12==10) System.out.print("Ngo"); if(n%12==11) System.out.print("Mui"); if(n%12==0) System.out.print("Than"); if(n%12==1) System.out.print("Dau"); if(n%12==2) System.out.print("Tuat"); if(n%12==3) System.out.print("Hoi"); } }
Chương trình giải phương trình bậc 2 - Code:
-
class PhuongTrinhBac2 { public static void main (String[] args) { float a=Integer.parseInt(args[0]); float b=Integer.parseInt(args[1]); float c=Integer.parseInt(args[2]); if(a==0) { if(b==0 && c==0) System.out.println("Phuong trinh vo so nghiem"); else if(b==0 && c!=0) System.out.println("Phuong trinh vo nghiem"); else if(a==0 && b!=0) { System.out.println("Phuong trinh Bac 1"); float kq=(-c)/b; System.out.println("Phuong trinh Bac 1 Ket qua la " + kq); } } if(a!=0) { System.out.println("Phuong trinh bac 2"); float delta=(b*b) - (4*a*c ); if(delta<0) System.out.println("Phuong trinh vo nghiem"); else if(delta==0) { System.out.println("Phuong trinh Co nghiem kep"); float x= -b/(2*a); System.out.println("Phuong trinh co nghiem x = "+x); } else { System.out.println("Phuong trinh co 2 nghiem phan biet"); double x1= (((-b)+(Math.sqrt(delta)))/(2*a)); double x2= (((-b)-(Math.sqrt(delta)))/(2*a)); System.out.println("Phuong trinh co nghiem x1 "+x1); System.out.println("Phuong trinh co nghiem x2 "+x2); } } } } | |
|
Admins Thái Thượng Hoàng
Tổng số bài gửi : 336 Age : 35 Đến từ : cát bụi Registration date : 03/04/2008
| Tiêu đề: Re: Tui khai trương một số bài trước nha Mon Sep 15, 2008 1:05 pm | |
| bài giải pt bậc 2 rất hay nhưng tài mắc 1 cái lỗi là xài "&&" rất nhiều nên hạn chế bớt và dùng 3 cái if thui trình bày ngắn chứ theo như zậy tất nhiên vẫn ra nhưng lỡ pt bậc 1xxx thì sao làm nỗi - Code:
-
class ptbậc2 { public static void main (string[]args) { float a=Integer.parseInt(args[0]); float b=Integer.parseInt(args[1]); float c=Integer.parseInt(args[2]); if(a==0) if(b==0) if(c==0) System.out.println("PT Vo So Nghiem") else System.out.println("PT Vo Nghiem") else float kq=-c/b System.out.println("PT Co Nghiem Kep"+kq) else System.out.println("Phuong trinh bac 2"); float delta=(b*b) - (4*a*c ); if(delta<0) System.out.println("Phuong trinh vo nghiem"); else if(delta==0) { System.out.println("Phuong trinh Co nghiem kep"); float x= -b/(2*a); System.out.println("Phuong trinh co nghiem x = "+x); } else { System.out.println("Phuong trinh co 2 nghiem phan biet"); double x1= (((-b)+(Math.sqrt(delta)))/(2*a)); double x2= (((-b)-(Math.sqrt(delta)))/(2*a)); System.out.println("Phuong trinh co nghiem x1 "+x1); System.out.println("Phuong trinh co nghiem x2 "+x2); } }
} | |
|
DAICATAI Thái Sư
Tổng số bài gửi : 31 Age : 36 Đến từ : Lòng Đất Registration date : 08/04/2008
| Tiêu đề: Re: Tui khai trương một số bài trước nha Mon Sep 15, 2008 8:12 pm | |
| Bài Oai hết 10 lỗi , mới fix lại nè , xem thử sao : - Code:
-
class PTB2 { public static void main (String[]args) { float a=Integer.parseInt(args[0]); float b=Integer.parseInt(args[1]); float c=Integer.parseInt(args[2]); if(a==0) { if(b==0) if(c==0) System.out.println("PT Vo So Nghiem"); else System.out.println("PT Vo Nghiem"); else { float kq=-c/b; System.out.println("PT Co Nghiem Kep"+kq); } } else System.out.println("Phuong trinh bac 2"); float delta=(b*b) - (4*a*c ); if(delta<0) System.out.println("Phuong trinh vo nghiem"); else if(delta==0) { System.out.println("Phuong trinh Co nghiem kep"); float x= -b/(2*a); System.out.println("Phuong trinh co nghiem x = "+x); } else { System.out.println("Phuong trinh co 2 nghiem phan biet"); double x1= (((-b)+(Math.sqrt(delta)))/(2*a)); double x2= (((-b)-(Math.sqrt(delta)))/(2*a)); System.out.println("Phuong trinh co nghiem x1 "+x1); System.out.println("Phuong trinh co nghiem x2 "+x2); } }
} | |
|
Sponsored content
| Tiêu đề: Re: Tui khai trương một số bài trước nha | |
| |
|