on tap javax

32 335 5
on tap javax

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

java

Java: Dạng 1: Bài 1: Class SoNguyen(){ Int giaTri; //sai chưa gán giá trị cho biến Int ktngto(){ Int i,dem=0; For(i=1,i<giaTri/2,i++)//sai cú pháp for(biến 1;điều kiện;biến 2){} If(i%2==0) dem+=1; If(dem==0) return 0; Else return 1; }} Bài 2: Class A extend B{ Int y,z; Final int tong(int a,int b,int c){ System.out.print(x); Return (a+b+c); }} Class B{ Private int x=20;//sai: kiểu private không được phép kế thừa Final int tong(int a,int b,int c){ Return (a+b+c); }} Bà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. Float diem1,diem2,diem3; Void DTB(float a,float b,float c){//sai: kiểu void không trả lại giá trị. Return(a+b+c); }} Bài 4: Class LinhKien(){ Int maso=”123”;//sai: giá trị số không đặt trong dấu nháy kép. String ten=”R1”; Float gia=100; String dvt=”chiec”; Float IN(){//sai: kiểu hàm không có giá trị trả về, sửa thành kiểu void IN(){} System.out.print(maso+””+ten+””+gia+” ”+dvt); }} Bài 5: Class main{ Final int x=0; 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ố Int n; String st; Try{ DataInputStream s=new DataInputStream(System.in); st=s.readLine() //sai: thiếu dấu ; }catch (IOException e){st=”0”;} Try{ x=Int.valueOf(st).intValue(); }catch (NumberFormatException e){} }} Dạng 2: Bài 1: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package dang2; import java.io.*; import java.lang.*; import java.util.*; class SV{ String masv; String hoTen; String ngaySinh; String diaChi; Float diem1; Float diem2; Float diem3; Float DTB; public static float nhapso()throws IOException{ float x; DataInputStream dis=new DataInputStream(System.in); try{ x=Float.parseFloat(dis.readLine()); }catch(NumberFormatException e){x=0;} return x; } public static String nhapchuoi(){ DataInputStream dis=new DataInputStream(System.in); String str; try{ str=dis.readLine(); }catch(IOException e){str=" ";} return str; } public void nhapSV() throws IOException{ System.out.print("Ho Ten: "); hoTen=nhapchuoi(); System.out.print("Ma Sinh Vien: "); masv=nhapchuoi(); System.out.print("Ngay Sinh: "); ngaySinh=nhapchuoi(); System.out.print("Dia Chi: "); diaChi=nhapchuoi(); System.out.print("diem 1: "); diem1=nhapso(); System.out.print("diem 2: "); diem2=nhapso(); System.out.print("diem 3: "); diem3=nhapso(); DTB=(diem1+diem2+diem3)/3; } public 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); } } /** * * @author le */ public class Bai1 { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here DataInputStream is=new DataInputStream(System.in); int i,j,k; System.out.print("nhap i="); i=Integer.parseInt(is.readLine()); SV sinhvien[]=new SV[30]; for(j=1;j<=i;j++){ System.out.println("nhap thong tin SV["+j+"]"); sinhvien[j]=new SV(); sinhvien[j].nhapSV(); } System.out.println("Danh sach SV:"); for(j=1;j<=i;j++){ System.out.println("thong tin SV["+j+"]"); sinhvien[j].in(); } System.out.print("sinh vien o thai nguyen\n"); for(j=1;j<=i;j++){ if("Thai Nguyen".equals(sinhvien[j].diaChi)) { sinhvien[j].in(); } } System.out.print("sinh vien diem cao nhat\n"); float z; k=1; z=sinhvien[1].DTB; for(j=2;j<=i;j++){ if(z<sinhvien[j].DTB){ z=sinhvien[j].DTB; k=j; } } sinhvien[k].in(); System.out.print("sinh vien sinh nam 1991:\n"); for(j=1;j<=i;j++){ if("1991".equals(sinhvien[j].ngaySinh)){ sinhvien[j].in(); } } } } Bai2: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package dang2; import java.io.*; /** * * @author le */ public class bai2 { /** * @paramargs the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here DataInputStream is=new DataInputStream(System.in); intx,y; System.out.print("nhap so phantumang: "); try{ x=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()); } int j=A[0]; inti=A[0]; for(y=1;y<x;y++){ if(j<A[y]){ j=A[y]; } if(i>A[y]){ i=A[y]; } } System.out.print("max= "+j); System.out.print("\nmin= "+i); int B[]=new int[60]; int k=0; for(y=0;y<x;y++){ intkt=0; for(i=2;i<=A[y]-1;i++){ if(A[y]%i==0){ kt+=1;}} if(kt==0) { B[k]=A[y]; k+=1; } } j=B[0]; i=B[0]; for(y=1;y<k;y++){ if(j<B[y]){ j=B[y]; } if(i>B[y]){ i=B[y]; } } System.out.print("\nmaxnguyen to= "+j); System.out.print("\nminnguyen to= "+i); i=0;j=0; for(y=0;y<x;y++){ if(A[y]%2==0){ i+=A[y]; } else{ j+=A[y]; . "+a[i]+ss.getInetAddress()); } int tong=0; for(inti=0;i<9;i++){ tong+=a[i]; } os.write(tong); }catch(IOExceptionie){System.out.print(ie);}. //sai: thiếu dấu ; }catch (IOException e){st=”0”;} Try{ x=Int.valueOf(st).intValue(); }catch (NumberFormatException e){} }} Dạng 2: Bài 1: /* * To change

Ngày đăng: 04/03/2013, 16:07

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan