diff --git a/homework/counts.java b/homework/counts.java new file mode 100644 index 0000000..ba5ec06 --- /dev/null +++ b/homework/counts.java @@ -0,0 +1,30 @@ +public class counts{ + public static void main(String[] args){ + int [] numbers = new int[100]; + int [] counts = new int[10]; + + for(int i = 0; i 0){ + a = number % 10; + number = number/ 10; + System.out.print( a ); + } + + } + + } +} diff --git a/homework/sumMatrix.java b/homework/sumMatrix.java new file mode 100644 index 0000000..ab18bec --- /dev/null +++ b/homework/sumMatrix.java @@ -0,0 +1,31 @@ +import java.util.Scanner; +public class sumMatrix{ +public static void main(String[] args){ + System.out.println("import:"); + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + double[][] matrix = new double[n][n]; + for(int i = 0;i balance) + balance = balance - money; +else + System.out.println("you donnot have enough money"); +} +public void Deposit(double money){ + balance += money; +} + + + + + +} \ No newline at end of file diff --git a/homework1105/arraysort.java b/homework1105/arraysort.java new file mode 100644 index 0000000..54f3327 --- /dev/null +++ b/homework1105/arraysort.java @@ -0,0 +1,39 @@ +import java.util.ArrayList; +import java.math.*; +public class arraysort{ + public static void main(String[] args){ + ArrayList list = new ArrayList<>(); + list.add(3); + list.add(9); + list.add(5); + list.add(7); + list.add(1); + sort(list); + +} + +public static void sort(ArrayListlist){ + for(int i = 0;i < list.size();i++){ + Number min = list.get(i); + int minindex = i; + + for(int j = i+1;j list.get(j).intValue()){ + min = list.get(j); + minindex = j; + } + } + + if(minindex != i){ + list.set(minindex,list.get(i)); + list.set(i,min); + } + + } + for (int a =0; a < list.size();a++){ + System.out.print(list.get(a) + ""); + } +} + + +} \ No newline at end of file diff --git a/homework1105/clone.java b/homework1105/clone.java new file mode 100644 index 0000000..46d4cda --- /dev/null +++ b/homework1105/clone.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.math.*; +public class clone{ +public static void main(String[] args){ + courseclone course1 = new courseclone("data structures"); + courseclone course2 = (courseclone) course1.clone(); + course1.addStudent("S1"); + course1.addStudent("S2"); + course1.addStudent("S3"); + course2.addStudent("S4"); + course2.addStudent("S5"); + System.out.println(course1.getNumberOfStudents()); + System.out.println(course2.getNumberOfStudents()); + +} +} + class courseclone implements Cloneable{ + private String courseName; + private String[] students = new String[100]; + private int numberOfStudents; + + public courseclone(String courseName){ + this.courseName = courseName; + } + public void addStudent(String student){ + students[numberOfStudents] = student; + numberOfStudents++; + } + public String[] getStudents(){ + return students; + } + public int getNumberOfStudents(){ + return numberOfStudents; + } + public String getCourseName(){ + return courseName; + } + +@Override +public Object clone(){ + try{ + courseclone c = (courseclone)super.clone(); + c.students = new String[100]; + + + return c; + + }catch(CloneNotSupportedException ex){ + return null; + } +} + +} + + + + diff --git a/homework1105/testdate.java b/homework1105/testdate.java new file mode 100644 index 0000000..1b0a47c --- /dev/null +++ b/homework1105/testdate.java @@ -0,0 +1,13 @@ +import java.util.Date; +public class testdate{ + public static void main(String[] args){ + long time = 10000; + Date date = new Date(time); + + for(int i = 0;i<7;i++){ + time = time* 10; + date.setTime(time); + System.out.println("when the elapsetime is:"+ time + "the date is: " + date.toString()); + } + } +} \ No newline at end of file diff --git a/homework1113/hashtest1.java b/homework1113/hashtest1.java new file mode 100644 index 0000000..e442a79 --- /dev/null +++ b/homework1113/hashtest1.java @@ -0,0 +1,71 @@ +import java.io.InputStream; +import java.io.File; +import java.io.FileInputStream; +import java.security.MessageDigest; +import java.io.FileNotFoundException; +public class hashtest1{ + public static void main(String[] args){ + try{ + String path = "G:\\java"; + byte[] sha1 = fileHash(path); + String code = ""; + for(int i = 0;i0){ + md.update(buffer,0,length); + + } + }while(length != -1); + fis.close(); + } + catch(Exception e){ + e.printStackTrace(); + } + + + } + if(fs[i].isDirectory()){ + System.out.println("Directory:"+fs[i].getName()); + fileHash(path + File.separator + fs[i].getName()); + } + }//for寰幆 + return md.digest(); + + } + catch(Exception e){ + e.printStackTrace(); + return null; + } + }//fileHash + + + +} \ No newline at end of file