JAVA5实习报告.docx_第1页
JAVA5实习报告.docx_第2页
JAVA5实习报告.docx_第3页
JAVA5实习报告.docx_第4页
JAVA5实习报告.docx_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验五 Java 输入输出流 1实验目的(1) 掌握输入输出流的总体结构;(2) 掌握流的概念;(3) 了解各种流(包括文件流、管道流、连接文件、过滤流、对象的序列化、随机访问)的使用。2实验内容实验题1 编写一个Java Application程序,打印命令行输入的所有参数。基本要求 编写完整程序。程序源代码如下:import java.util.Scanner;public class Test1 public Test1() / TODO Auto-generated constructor stubpublic static void main(String args) / TODO Auto-generated method stubScanner SCA= new Scanner(System.in);System.out.println(请输入所有参数:);String a=SCA.nextLine();System.out.println(输入所有参数为:);System.out.println(a);运行结果如下:实验题2 阅读下面程序,叙述其功能package .nwsuaf.jp;import java.io.FileReader;import java.io.IOException;public class FileViewer public static void main(String args) System.out.println(Please enter the file path:);try String fileName = ;while(true) int readByte = System.in.read();if(readByte = -1 | readByte = r)break;fileName += (char) readByte;/ Reads the file and prints it to the System.out stream.char buffer = new char20;FileReader reader = new FileReader(fileName);while(true) int length = reader.read(buffer);if(length 0)String s=new String(bytes,0,rs);System.out.println(s);tryif(!file2.exists()file2.createNewFile();FileOutputStream fos=new FileOutputStream(file2);fos.write(bytes, 0, 1024);fos.flush();fos.close();catch(IOException e)e.printStackTrace();fis.close(); catch(IOException e)e.printStackTrace();运行结果如下:基本要求 编写完整程序。实验题 4 水仙花数。所谓水仙花数是指一个3位数,其各位数字立方和等于该数本身。例如,153就是一水仙花数,因为153 = 13+53+33。 请计算出100万以内所有的水仙花数,并以一行一个水仙花数的格式保存到文本文件data.txt中。输出格式如下:153 = 1*1*1 + 5*5*5 + 3*3*3程序源代码如下:import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;public class shuixian public static void main(String args) throws IOException File file=new File(data.txt);FileWriter fos = new FileWriter(file);BufferedWriter BW= new BufferedWriter(fos);tryif(!file.exists()file.createNewFile();for(int i=100;i1000;+i)int a1=i/100;int c1=(i-a1*100)/10;int d1=i-(a1*100+c1*10);if(i=a1*a1*a1+c1*c1*c1+d1*d1*d1) BW.write(i+=+a1+*+a1+*+a1+c1+*+c1+*+c1+d1+*+d1+*+d1); BW.newLine(); BW.close();System.out.println();catch(IOException e)e.printStackTrace();运行结果如下:实验题 5 写一程序统计纯文本文件“Early-Precaution.txt”的大写字母、小写字母个数,并将所有小写字母转换为大写字母,输出到result.txt程序源代码如下:import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileWriter;public class Test5 public void ReadFile(String filename)int BigChar=0;int SmallChar=0;tryFileInputStream fis= new FileInputStream(filename);byte B=new byte1024;int len=fis.read(B);String a=new String(B,0,len);for(int i=0;i=41&c=97&c=122)SmallChar+;c=(char)(int)c-46);System.out.println(大写字母个数:+BigChar+小写字母个数:+SmallChar);tryFile fis1= new File(result.txt);if(!fis1.exists()fis1.createNewFile();FileWriter F=new FileWriter(fis1);BufferedWriter BW= new BufferedWriter(F);String b=a.toUpperCase();F.write(b);F.flush();F.close();fis.close();catch(Exception e)e.printStackTrace();catch(Exception e)e.printStackTrace();public static void main(St

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论