Bài 1:
import java.util.*;
public class Bai1
{
public void GT(int n)
{
int gt = 1;
for(int i=1;i<=n;i++)
gt *= i;
System.out.println("\nGT la: "+gt);
if(gt%5==0)
{
System.out.println("\nHinh vuong la:");
for(int i=1;i<=n*n;i++)
{
System.out.printf("%02d ",i);
if(i%5==0)
System.out.print("\n");
}
}
}
public static void main(String []args)
{
Scanner input = new Scanner(System.in);
System.out.print("\nTinh gia thua:\nn = ");
int n = input.nextInt();
Bai1 b1 = new Bai1();
b1.GT(n);
}
}
////////////////////////////////////////////////////
Bài 2:
import java.util.*;
public class Bai2
{
public String ten;
public float diemToan;
public float diemLy;
public float diemHoa;
public float dtb;
public void NhapTen()
{
Scanner input = new Scanner(System.in);
System.out.print("\nNhap ten: ");
ten = input.nextLine();
}
public void ShowTen()
{
System.out.print("\nTen cua ban:"+ten);
}
public void NhapDiem()
{
Scanner input = new Scanner(System.in);
System.out.print("\nNhap diem cua ban!\nDiem toan: ");
diemToan = input.nextFloat();
System.out.print("Diem ly: ");
diemLy = input.nextFloat();
System.out.print("Diem hoa: ");
diemHoa = input.nextFloat();
dtb = (diemToan + diemLy + diemHoa)/3;
}
public void ShowDiem()
{
System.out.print("\nDiem cua ban la! ");
System.out.print("\nDiem toan: " + diemToan);
System.out.print("\nDiem ly: " + diemLy);
System.out.print("\nDiem hoa: " + diemHoa);
System.out.print("\nDtb: " + dtb);
}
public static void main(String[]args)
{
int n, m = 0; Bai2 b2 = new Bai2();
Scanner input = new Scanner(System.in);
while(m!=5)
{
System.out.print("\n\n1.Nhap ten.\n2.In ten.\n3.Nhap diem."+
"\n4.In diem.\n5.Thoat.\n\nLua chon: ");
n = input.nextInt();
switch(n)
{
case 1:
b2.NhapTen();
break;
case 2:
b2.ShowTen();
break;
case 3:
b2.NhapDiem();
break;
case 4:
b2.ShowDiem();
break;
case 5:
m = 5;
break;
}
}
}
}
////////////////////////////////////////////////////
Bài 3:import java.util.*;
public class Bai3
{
public int n;
public void ProcessBai3()
{
Scanner input = new Scanner(System.in);
System.out.print("\nSo tang: ");
n = input.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
System.out.print(" ");
for(int j=1;j<=i;j++)
System.out.print(" "+(int)Math.pow(2,j-1));
for(int j=i-1;j>0;j--)
System.out.print(" "+(int)Math.pow(2,j-1));
System.out.println("");
}
}
public static void main(String[]args)
{
Bai3 b3 = new Bai3();
b3.ProcessBai3();
}
}
/////////////////////////////////////////////////////
Bài 4:
import java.util.*;
public class Bai4
{
public int n;
public void ProcessBai4()
{
Scanner input = new Scanner(System.in);
System.out.print("\nSo tang: ");
n = input.nextInt();
System.out.println("\n\nA.");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
System.out.print("* ");
System.out.println("");
}
System.out.println("\n\nB.");
for(int i=n;i>=1;i--)
{
for(int j=i;j>=1;j--)
System.out.print("* ");
System.out.println("");
}
System.out.println("\n\nC.");
for(int i=n;i>=1;i--)
{
for(int j=1;j<=n-i;j++)
System.out.print(" ");
for(int j=i;j>=1;j--)
System.out.print("* ");
System.out.println("");
}
System.out.println("\n\nD.");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
System.out.print(" ");
for(int j=1;j<=i;j++)
System.out.print("* ");
System.out.println("");
}
}
public static void main(String[]args)
{
Bai4 b4 = new Bai4();
b4.ProcessBai4();
}
}
Có j anh em cùng góp ý nha ^_^
thank nhiều