java
Trang 2Bài 3:
Class SV{
String hoTen=”Nguyen Thanh Truc”;
Int tuoi=”2”;//sai: giá trị không đặt trong dấu nháy kép
Public abstrac void tong(){
Int x=20,s=0;//sai: tham biến x không thay đổi được
For(i=1;i<x;i++) s+=1;}
Public static void main(String arg){//sai: thiếu dấu [] vì là mảng số
Trang 3* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 4public static String nhapchuoi(){
DataInputStream dis=new DataInputStream(System.in); String str;
Trang 5public void in(){
System.out.println("Ho Ten: "+hoTen);
System.out.println("Ma sinh vien: "+masv);
System.out.println("Ngay Sinh: "+ngaySinh);
System.out.println("Dia Chi: "+diaChi);
System.out.println("Diem 1:"+diem1+" Diem 2:"+diem2+" Diem 3:"+diem3); System.out.println("Diem TB: "+DTB);
}
}
/**
*
Trang 7for(j=1;j<=i;j++){
if("Thai Nguyen".equals(sinhvien[j].diaChi)) { sinhvien[j].in();
}
}
}
}
Trang 8/*
* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 9x=Integer.parseInt(is.readLine());}catch(IOException e){x=0;}
int A[]=new int[60];
for(y=0;y<x;y++){
System.out.print("nhapphantu A["+y+"]: "); A[y]=Integer.parseInt(is.readLine()); }
Trang 12System.out.print("\ntongcac so o vi tri chan: "+i);
}
}
Bài 3:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 13System.out.print("nhapkichthuoc ma tranvuong: "); m=Integer.parseInt(is.readLine());
Trang 14int B[][]=new int[40][40];
Trang 15int C[]=new int [40];
z=0;
for(i=1;i<=m;i++){
k=A[i][i];
Trang 16int D[]=new int[40];
Trang 17* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 18* @author le
*/
public class Bai1server {
public final static int port=55;
int tong=0;
for(inti=0;i<9;i++){
tong+=a[i];
Trang 19* To change this template, choose Tools | Templates
* and open the template in the editor
public class bai1client {
public static final int port=55;
Trang 20// TODO code application logic here
DataInputStream dis=new DataInputStream(System.in);try{
Socket s=new Socket("LocalHost",port);
}
Bài 2:
Server;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 21public class bai2server {
public final static int port=50;
/**
* @paramargs the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.print("\nchuoinhanduoc: "+st);
Trang 22System.out.print("\nchuoiduocchuyendoi: "+str);os.writeUTF(str);
}catch(IOExceptionie){System.out.print(ie);} }
* To change this template, choose Tools | Templates
* and open the template in the editor
public class bai2client {
public final static int port=50;
/**
* @paramargs the command line arguments */
Trang 23public static void main(String[] args) {
// TODO code application logic here
DataInputStream dis=new DataInputStream(System.in);
try{
while(true){
Socket s=new Socket("LocalHost",port);
DataInputStream is=new DataInputStream(s.getInputStream());DataOutputStreamos=new DataOutputStream(s.getOutputStream()); String st,str;
* To change this template, choose Tools | Templates
* and open the template in the editor
*/
Trang 24public class bai3server {
public final static int port=50;
/**
* @paramargs the command line arguments */
public static void main(String[] args) {
// TODO code application logic here String st,str;
try{
ServerSocketss=new ServerSocket(port);while(true){
try{
Socket s=ss.accept();
Trang 25DataInputStream is=new DataInputStream(s.getInputStream());DataOutputStreamos=new DataOutputStream(s.getOutputStream());st=is.readUTF();
* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 26*
* @author le
*/
public class bai3client {
public final static int port=50;
/**
* @paramargs the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
DataInputStream dis=new DataInputStream(System.in);
try{
while(true){
Socket s=new Socket("LocalHost",port);
DataInputStream is=new DataInputStream(s.getInputStream());DataOutputStreamos=new DataOutputStream(s.getOutputStream()); String st,str;
Trang 27Bìa 19:
Server:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor
public class Bai19 {
public final static int port=55;
Trang 28DataInputStream is=new DataInputStream(s.getInputStream());DataOutputStreamos=new DataOutputStream(s.getOutputStream()); String st;
Trang 29* To change this template, choose Tools | Templates
* and open the template in the editor
*/
packagethuchanh;
Trang 30public class bai19client {
public final static int port=55;
/**
* @paramargs the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
DataInputStream dis=new DataInputStream(System.in);
try{
while(true){
Socket s=new Socket("127.0.0.1",port);
DataInputStream is=new DataInputStream(s.getInputStream());DataOutputStreamos=new DataOutputStream(s.getOutputStream());System.out.print("nhap so: ");
Trang 31* To change this template, choose Tools | Templates
* and open the template in the editor
Trang 32Runtime rt=Runtime.getRuntime();
Process p=rt.exec("logoff");// câulệnh”tắtmáykhỏeđộngmáy, khởiđộngchương trình.exe” }
}