⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch8ex10.java

📁 JAVA程序设计 丁岳伟 彭敦陆编 高等教育出版社 第7---11章程序
💻 JAVA
字号:
import java.io.*;
public class ch8ex10{
	public static void main(String[]args){
		int x;
		try{
			DataOutputStream fout=new DataOutputStream(new FileOutputStream("grades.dat",true));
			for(int j=0;j<200;j++){
				x=(int)(Math.random()*1000000)%100;
				fout.writeInt(x);
			}
			fout.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		int fail=0;	int pass=0;
		int levelA=0;int levelB=0;
		int levelC=0;
		try{
			DataInputStream fin=new DataInputStream(new FileInputStream("grades.dat"));
			while(fin.available()>0){
				x=fin.readInt();
				if(x<60) fail++;
				else if(x>=60&&x<70) pass++;
					else if(x>=70&&x<80) levelC++;
						else if(x>=80&&x<90) levelB++;
							else levelA++;
			}
			fin.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println("Class A level:  "+levelA);
		System.out.println("Class B level:  "+levelB);
		System.out.println("Class C level:  "+levelC);
		System.out.println("Pass:  "+pass);
		System.out.println("Fail:  "+fail);
		try{
			DataInputStream fin=new DataInputStream(new FileInputStream("grades.dat"));
			DataOutputStream fout1=new DataOutputStream(new FileOutputStream("fails.dat"));
			DataOutputStream fout2=new DataOutputStream(new FileOutputStream("temp.dat"));
			while(fin.available()>0){
				x=fin.readInt();
				if(x<60)
					fout1.writeInt(x);
				else
					fout2.writeInt(x);
			}
			fin.close();
			fout1.close();
			fout2.close();
			File oldFile=new File("grades.dat");
			oldFile.delete();
			File newFile=new File("temp.dat");
			newFile.renameTo(oldFile);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -