这是我的三道题代码,大家要是不会的看看,会的话可以指点指点{:2_32:}共同进步
1.public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<>();
Random r = new Random();
System.out.println("评委打分分别为:");
for(int i = 0 ; i < 6 ; i++){
int x = r.nextInt(10) + 1;
al.add(x);
System.out.print(x + "分 ");
}
System.out.println();
Collections.sort(al);
al.remove(0);
al.remove(al.size() - 1);
double sum = 0 ;
for(Integer i : al){
sum = sum + i ;
}
double count = sum/al.size();
System.out.println("该选手最终得分为:" + count + "分");
}
2.package test;
public class Test2 {
public static void main(String[] args) {
final Jiaoti j = new Jiaoti();
new Thread() {
public void run() {
for (int i = 0; i < 26; i++) {
try {
j.print1();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
new Thread() {
public void run() {
for (int i = 0; i < 26; i++) {
try {
j.print2();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
}
class Jiaoti {
static int flag = 1;
public static int num = 1;
public static char ch = 'A';
public void print1() throws InterruptedException {
synchronized (this) {
if (flag != 1) {
this.wait();
}
for (int i = 0; i < 2; i++) {
System.out.print(num++);
}
flag = 2;
this.notify();
}
}
public void print2() throws InterruptedException {
synchronized (this) {
if (flag != 2) {
this.wait();
}
char c = (char) ch++;
System.out.print(c);
flag = 1;
this.notify();
}
}
}
3.public static void main(String[] args) throws IOException {
String oldPath = "d:\\aaa";
String newPath = "d:\\bbb";
String fileFormat = "avi";
Test3.copy(oldPath, newPath, fileFormat);
ArrayList<String> al = new ArrayList<>();
for(File f : new File(oldPath).listFiles()){
if(f.isFile() && f.getName().endsWith(fileFormat)){
al.add(f.getName());
}
}
for(String s : al){
System.out.println(s);
}
}
public static void copy(String oldPath, String newPath, String fileFormat) throws IOException{
File file = new File(oldPath);
File[] fils = file.listFiles();
for(File f: fils){
if(f.isFile() && f.getName().endsWith(fileFormat)){
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = new FileOutputStream(new File(newPath, f.getName()));
int len;
while((len = fis.read()) != -1){
fos.write(len);
}
fis.close();
fos.close();
}
}
}
|