Tạo hai file *.java!!!!! 1/ Phương trình bậc hai: file PTB2.java: import java.util.

Scanner; public class PTB2 { int a, b, c; public PTB2(){ a=b=c=0; } public PTB2(int a,int b, int c){ this.a=a; this.b=b; this.c=c; } public void Nhap(){ Scanner q = new Scanner(System.in); System.out.print("Nhap a,b,c: "); a=q.nextInt(); b=q.nextInt(); c=q.nextInt(); } public void GPT(){ double d, x1,x2; d = (b*b) - (4*a*c); if(a==0&&b!=0){ x1 = -c/a; System.out.println("Phuong trinh co }else if(a==0&&b==0&&c==0){ System.out.println("Phuong trinh vo }else if(a==0&&b==0&&c!=0){ System.out.println("Phuong trinh vo }else if(a!=0){ if(d>0){ x1 = (-b + Math.sqrt(d))/(2*a); x2 = (-b - Math.sqrt(d))/(2*a); System.out.println("Phuong trinh co "+x2); }else if(d==0){ x1 = -b/(2*a); System.out.println("Phuong trinh co }else if(d<0){ System.out.println("Phuong trinh vo } } } } file TestPTB2.java: public class TestPTB2 { public static void main(String[]args){ PTB2 a = new PTB2(); a.Nhap(); a.GPT(); } } 2/ Hình tròn: file Hinhtron.java:

nghiem la: "+x1); so nghiem"); nghiem");

hai nghiem: \n Nghiem 1: "+x1+"\n Nghiem 2:

nghiem kep x1=x2= "+x1); nghiem");

java: public class TestHT { public static void main(String[] args){ Hinhtron b = new Hinhtron(). . System. System.util. dt = r*r*Math. } public void nhap(){ Scanner q = new Scanner(System. r=q.println("Chu vi: "+cv).PI*r. double r. System. System. dt.b.print("Nhap ban kinh: "). cv = 2*Math.out. } public HCN(int a. b.Scanner.int b){ this. } public void giai(){ double cv. } public void nhap(){ Scanner q = new Scanner(System.giai(). public class HCN { int a.nhap().out.Scanner. dt = a*b.out.chieu rong: ").nextDouble().PI. System. public HCN(){ a=b=0. } } file TestHT. public class Hinhtron { // final double PI = 3.out. b=q.util.a=a.print("Nhap chieu dai.java: import java.println("Dien tich hinh tron: "+dt). public Hinhtron(){ r=0. } public void gt(){ double cv. cv = (a+b)*2.nextInt().println("Dien tich: "+dt).r=r. a=q.nextInt(). } } 3/Hình chữ nhật: file HCN. System.out.b=b. dt.14. this.out.import java.in). } public Hinhtron(double r){ this.println("Chu vi hinh tron: "+cv).in). b.

} public double BSCNN(double a. } public phanso(double a. double b){ double us.nextDouble(). a = q. a. phanso a = new phanso(). double tu. int chucnang. System.in).util. System. mau = b/us.println("Phan so: "+tu+"/"+mau). tu = a/us.b=b. } public void nhap(){ Scanner q = new Scanner(System. b = q. public phanso(){ a=b=0. us = BSCNN(a.double b) { while(a!=b){ if (a > b) a=a-b. } public void rutgon(double a. else b = b-a. System. phanso b = new phanso().Scanner. this.nhap(). } } 4/ Phân số: file phanso. a.nhap().java: import java.out.gt().nextDouble().out. } } file TestPhanso.in).a=a.print("Nhap mau so: ").java: import java.out.} } file TestHCN. mau.java: public class TestHCN { public static void main(String[] agrs){ HCN a = new HCN(). a.util.Scanner.b). public class phanso { double a. . public class TestPhanso { public static void main(String[] args){ Scanner q = new Scanner(System. } return a.print("Nhap tu so: ").double b){ this.b.

println("1.exit(0). } case 2:{ double tu.out.println("4. mau. mau = (a.println("Phan so: "+tu+"/"+mau).out.out.a*b.println("Hay chon mot trong nhung chuc nang sau: "). System.out. System.out.rutgon(tu.a).mau)==(int)a.a. chucnang = q.println("Phan so: "+tu+"/"+mau).BSCNN(tu.out. } case 2:{ System. System. Thoat chuong trinh").BSCNN(tu. } case 3:{ double tu. System. if(a.BSCNN(tu. mau.print("Nhap phan so: ").exit(0).print("Hay chon chuc nang:").println("2.b)+(a.mau)){ a. System. tu = a. System.mau)==(int)a.println("1. }else System. if(a.out. mau = (a. r = q.a/b. mau).rutgon(tu.b). mau. Phep cong"). b.out.rutgon(a.a*b. Phep nhan"). System.b).println("Phan so: "+tu+"/"+mau).out. De thoat").println("0.nextInt(). mau = (a. break. tu = a. }else System.println("3.nextInt(). Tinh phan so").a.out. Phep tru").do{ System.b). System.println("Hay chon phep tinh:").a*b.rutgon(tu. } case 4:{ double tu. switch(r){ case 1:{ double tu.b)-(a. Rut gon phan so").a. tu = (a. switch(chucnang){ case 1:{ a.b*b.mau)){ a. System.out.nhap().b*b.b*b.a.b). mau.out. System.b).b*b.out.b*b. mau).mau)){ a.b/b.a).out. Phep chia"). System. System.println("0. int r.out.exit(0).print("Hay chon: "). mau = (a.BSCNN(tu. System. tu = (a. if(a.BSCNN(tu. . mau).BSCNN(tu.mau)==(int)a. do{ System.println("2. }else System.out.

System.if(a. Nhan").out.Scanner. import java.println("Phep cong: "+sum). Cong"). System. Chia"). BufferedReader keyboard = new BufferedReader (new InputStreamReader (System. int c. System. System. System.in)) . } } No comments Code Bài Tập Java Thursday. Nhan n de ket thuc").mau)){ a.out.print("Nhap so a: ").BSCNN(tu.out.print("Nhap so b!=0: "). public class Calculator { public static void main(String[] args) throws IOException{ Scanner in = new Scanner(System.println("3.println("0. System. int chucnang. October 7.out. System. Ket thuc"). do{ double d.*. System. System. sum=a+b.out.println("4. System.println("2. break. .nextDouble(). mau).println("0.println("2.BSCNN(tu. b.nextDouble().in).out. a = in. do{ double a. b = in. System. System.out. } } }while(r!=0).out. System.out.util. 2010 1:43:35 PM java Bài 1: Calculator.print("Nhap so: ").nextInt(). switch(chucnang){ case 1:{ double sum.out. }else System. import java. } } }while(chucnang!=0).nextDouble().print("Chon phep tinh: "). Cong").rutgon(tu.println("1.out.out. System. Tru").mau)==(int)a.exit(0).io. String input. d =in. chucnang = in.out.println("Phan so: "+tu+"/"+mau). package calculator. Tru").out.println("1.

input = keyboard. BufferedReader keyboard = new BufferedReader (new InputStreamReader (System. break.println("Ket qua: "+sum).out.out.readLine().println("Nhap lai!"). System.out. System.print("Chon phep tinh: ").out.out. }while(input. System.equals("n")). System. System. c = in.out. Nhan").out. String input. break. Nhan n de ket thuc"). System. Tru"). System. hieu = a-b.out.in)) . break.d. } } System. } case 2:{ .println("4. Chia"). Cong"). System.out. System.out. System. } case 2:{ sum = sum .println("3.out.println("4. else System. c = in.out.print("Chon phep tinh: ").equals("y")).println("2.println("Ket qua: "+sum). d =in. break.print("Nhap so: "). switch(c){ case 1:{ sum = sum + d.nextDouble().nextInt(). break.out.out.out. System. } case 4:{ if(d!=0) sum = sum / d.out. System.println("0. } case 3:{ sum = sum * d. System.println("Ket qua: "+sum).println("3. int c.print ("Ban co muon tinh tiep khong (y/n)?: ").println("Ket qua: "+hieu). System.println("Phep tru: "+hieu). Nhan"). switch(c){ case 1:{ hieu = hieu + d.println("1. break.out.println("Ket qua: "+sum).nextInt(). if(input. System. } case 2:{ double hieu. Chia").out. do{ double d.System.

.out. Cong"). } case 3:{ tich = tich * d.println("Phep nhan: "+tich). break. } case 3:{ hieu = hieu * d.print("Chon phep tinh: ").out. break. System. System. System. break.println("2.println("Ket qua: "+tich). System. c = in.out.out.print ("Ban co muon tinh tiep khong (y/n)?: ").out.equals("y")).readLine(). do{ double d. Nhan").println("Ket qua: "+hieu).out. break.out. Tru"). d =in. String input.out.d.out.println("4.println("Ket qua: "+hieu).print("Nhap so: "). int c.d. System. switch(c){ case 1:{ tich = tich + d. System.out.nextDouble(). } case 3:{ double tich. } case 4:{ if(d!=0) tich = tich / d.out. else System.out.out. System. Chia"). break. System. input = keyboard.println("Nhap lai!"). }while(input.in)) .nextInt(). System.hieu = hieu .println("1. System.println("0.println("Ket qua: "+hieu). if(input. System. } case 4:{ if(d!=0) hieu = hieu / d.out. System. tich = a*b.println("Ket qua: "+tich). } }System. break.out. break.println("3. System.println("Ket qua: "+tich).equals("n")). BufferedReader keyboard = new BufferedReader (new InputStreamReader (System. System. } case 2:{ tich = tich .out. Nhan n de ket thuc").

out.print ("Ban co muon tinh tiep khong (y/n)?: ").println("Ket qua: "+t).out.print ("Ban co muon tinh tiep khong (y/n)?: "). Nhan"). System. if(b!=0){ t = a/b. BufferedReader keyboard = new BufferedReader (new InputStreamReader (System. } else System.out. c = in. } case 2:{ t = t .out.out.equals("y")).println("Ket qua: "+tich).out.println("2. } case 4:{ double t. System.println("Nhap lai so: ").out.out. System. .println("3.out.out. input = keyboard.out.equals("y")).out.in)) .nextInt(). System. int c.println("Nhap lai!"). break. System.out.out.out.println("Ket qua: "+t). switch(c){ case 1:{ t = t + d. }while(input. Chia").out. System. if(input. System.println("Ket qua: "+t). System. do{ double d.print("Nhap so: ").equals("n")). break. } }System. System. } }System.readLine().out.readLine().println("1. System. break. String input. }while(input.println("0.d.out.println("Nhap lai!"). if(input.equals("n")).nextDouble(). System. Nhan n de ket thuc"). } case 3:{ t = t * d. System.println("4. break. input = keyboard.else System. break. System. } case 4:{ if(d!=0) t = t / d.print("Chon phep tinh: "). break.println("Phep Chia: "+ t). else System. break. d =in. Tru"). Cong").println("Ket qua: "+t).

public class tongtu1denN { public static void main(String[] args) { Scanner in = new Scanner(System. n = in.out. return true. import java.in). public class KTSNT { public static boolean KTSNT(int x){ for(int i=2.println("Nhap sai").nextInt().println("BSCNN Divisior of a. System. } return a. System.b)). b) ). } } Bài 2: Ước chung nhỏ nhất . n = c. int n.out.Scanner.out.out. System. . package baitap2.println(n + " khong la so nguyen to").out.Scanner. } public static void main(String[] args) { Scanner c = new Scanner(System. else System.i++) if(x%i==0) return false.b :" + USCLN(a.nextInt(). public class USCNN_BSCLN { public static int BSCNN(int a.out.util. } } }while(chucnang!=0). int s=0.println("Enter a.in). System.b:"+ BSCNN(a.Bội chung lớn nhất package uscln_bscnn.out. import java. } public static void main(String[] args){ Scanner input = new Scanner(System. } public static int USCLN(int a.util. int n.println(n + " la so nguyen to"). int b= input. int a = input. b)). System. else b = b-a.nextInt(). } } Bài 3: Kiểm tra số nguyên tố package ktsnt. } Bài 4: Tổng từ 1 ñến N.util.out.int b) { while(a!=b){ if (a > b) a=a-b.int b){ return((a*b)/BSCNN(a.Scanner.in).} default: { System.println("USCLN Multiple of a.b ").print("Nhap so: ").nextInt().i<x. import java. if(KTSNT(n)) System.print("Nhap so n: ").

public class hinhtron { public static void main(String[] args) { Scanner q = new Scanner(System. } } Bài 5: Fibonacci của n. n = q. final double PI = 3. s = Fibo(n). public class f_n { public static long Fibo(long n){ long s=1.println("Nhap so n: "). System.println("Fibonacci cua so n la: "+s).i<=n.util. long s=0. double cv.in).out. System. package insochinhphuong.out. System.util.out.out.println("Nhap ban kin: "). int a. System. else { s=Fibo(n-1)+Fibo(n-2). } } Bài 6: In ra số chính phương của n. System. dt = r*PI*r. d=b*b.nextDouble().dt. import java.d.nextInt(). if(n==0||n==1) return s.print("Nhap so a: ").b. a=in. System. int c.for(int i=0.util.*.println("So chinh phuong cua "+a+" la: "+c). System.out. System. package fnfn1fn2. } } Bài 7: Chu vi.nextInt(). public class Insochinhphuong { public static void main(String[] args) { Scanner in = new Scanner(System. package hinhtron.i++) s=s+i.in).Scanner.println("So chinh phuong cua "+b+" la: "+d). . int n. return s. import java. diện tích hình tròn. r = q. c=a*a.Scanner.out. b=in.14.println("Tong tu 1 den "+n+" la: "+s).nextInt(). } } public static void main(String[] args) { Scanner q = new Scanner(System.print("Nhap so b: "). double r.in). import java.out.out. cv = 2*PI*r.

double x1. public class TimMax { .*. import java. x2=(-b-Math. } } else if(a==0&&b==0&&c==0){ System. package ptb1. a = q.println("Phuong trinh co nghiem kep: "+x).println("Phuong trinh co nghiem: "+x).nextDouble().out.out. Min của 4 số package TimMax.c: ").println("Chu vi hinh tron la: "+cv).print("Nhap a.println("Dien tich hinh tron la: "+dt). } } Bài 8: Phương trình bậc nhất. System. System.b: ").out. } else if (a!=0){ d = (b*b)-(4*a*c). System. import java. } } } Bài 10: Tìm Max.nextDouble(). double a. System. a = q.c.in).out.println("Phuong trinh co hai nghiem: x1 la: "+x1+" x2 la: "+x2). System.x2.out.System.print("Nhap a. } else if(d==0){ x = -c/(2*a).sqrt(d))/(2*a).println("Phuong trinh co nghiem la: "+x).util. public class PTB1 { public static void main(String[] args) { Scanner q = new Scanner(System.out.b.out. import java. b = q. c = q. public class PTB2 { public static void main(String[] args) { Scanner q = new Scanner(System. System.Scanner. package ptb2. if(d>0){ x1=(-b+Math. if(a!=0){ x = -b/a.nextDouble(). }else if(d<0){ System. } else System.nextDouble().*. System.x.println("Phuong trinh vo nghiem"). if(a==0&&b!=0){ x = -c/b.in). double x.util.sqrt(d))/(2*a).nextDouble().util.b.out. } } Bài 9: Phương trình bậc 2. double a. b = q.out.d.println("Phuong trinh vo nghiem").println("Phuong trinh vo so nghiem").b.out.out.

in).print("Nhap so d: "). int max= max1>max2?max1:max2. int max1= a>b?a:b.print("Nhap so a: ").out.println("So lon nha la: "+max). System.nextInt().println("So nho nhat la: "+min).nextInt(). } } . int min=min1<min2?min1:min2.print("Nhap so b: "). d=in. int min1=a<b?a:b. int b. System.print("Nhap so c: "). System. int min2=c<d?a:b.out.nextInt().public static void main(String[] args) { Scanner in = new Scanner(System. int max2= c>d?c:d.out. System.out. System. int a.nextInt(). a=in. c=in. System.out.d. b=in.out.c.

Sign up to vote on this title
UsefulNot useful