《Java语言程序设计与数据结构》编程练习答案(第十七章)

英文名:Introduction to Java Programming and Data Structures, Comprehensive Version, 11th Edition

17.1

import java.io.*;public class book {public static void main(String[] args)throws Exception{File dst = new File("Exercise17_01.txt");FileWriter fw = new FileWriter(dst,true);try(PrintWriter output = new PrintWriter(fw);){for(int i=0;i<100;i++) {output.print((int) (Math.random() * 100)+" ");}output.print('\n');}}
}

17.2

import java.io.*;public class book {public static void main(String[] args)throws Exception{try(FileOutputStream musashi = new FileOutputStream("Exercise17_02.dat",true);){for(int i=0;i<100;i++)musashi.write((int)(Math.random()*100));}}
}

17.3

import java.io.*;public class book {public static void main(String[] args)throws Exception{try(FileInputStream yamato = new FileInputStream("Exercise17_02.dat");){int v=0;while(yamato.read()!=-1)v++;System.out.print(v);}}
}

17.4

import java.util.*;
import java.io.*;public class book {public static void main(String[] args)throws Exception{File yukikaze = new File(args[0]);Scanner input = new Scanner(yukikaze);String nagato="";while(input.hasNext())nagato+=input.nextLine();input.close();try(DataOutputStream shimakaze = new DataOutputStream(new FileOutputStream(args[1]));){shimakaze.writeChars(nagato);}}
}

17.5

import java.util.*;
import java.io.*;public class book {public static void main(String[] args)throws Exception{int[] PoW = {1,2,3,4,5};Date KGV = new Date();double DoY = 5.5;try(ObjectOutputStream Bismark = new ObjectOutputStream(new FileOutputStream("Exercise17_05.dat"));){Bismark.writeObject(PoW);Bismark.writeObject(KGV);Bismark.writeDouble(DoY);}try(ObjectInputStream Tilpitz = new ObjectInputStream(new FileInputStream("Exercise17_05.dat"));){int[] ss= (int[])(Tilpitz.readObject());Date jj=(Date)(Tilpitz.readObject());double bb= Tilpitz.readDouble();for(int i=0;i<ss.length;i++)System.out.print(ss[i]+" ");System.out.println('\n'+jj.toString());System.out.print(bb);}}
}

17.8

public class book {public static void main(String[] args)throws Exception{RandomAccessFile eagle = new RandomAccessFile("Exercise17_08.dat","rw");eagle.writeInt(1);eagle.close();RandomAccessFile victory = new RandomAccessFile("Exercise17_08.dat","rw");int swordfish = victory.readInt();swordfish++;victory.setLength(0);victory.writeInt(swordfish);}
}

17.10

import java.util.*;
import java.io.*;public class book {public static void main(String[] args)throws Exception{System.out.print("Enter the src: ");Scanner input = new Scanner(System.in);String jj = input.next();System.out.print("Enter the num: ");int num = input.nextInt();RandomAccessFile src = new RandomAccessFile(jj,"r");src.seek(0);long llen = src.length()/num;for(int i=1;i<=num;i++){RandomAccessFile tmp = new RandomAccessFile(jj+"."+i,"rw");for(long j=0;j<llen;j++){int kk = src.read();if(kk==-1)break;elsetmp.write(kk);}tmp.close();}src.close();}
}

17.14

import java.util.*;
import java.io.*;public class book {public static void main(String[] args)throws Exception{System.out.print("Enter the src and dst: ");Scanner input = new Scanner(System.in);String jj = input.next();String mm = input.next();RandomAccessFile src = new RandomAccessFile(jj,"r");RandomAccessFile dst = new RandomAccessFile(mm,"rw");src.seek(0);for(int i=0;i<src.length();i++){int tmp=src.read();tmp+=5;dst.write(tmp);}src.close();dst.close();}
}

17.15

import java.util.*;
import java.io.*;public class book {public static void main(String[] args)throws Exception{System.out.print("Enter the src and dst: ");Scanner input = new Scanner(System.in);String jj = input.next();String mm = input.next();RandomAccessFile src = new RandomAccessFile(jj,"r");RandomAccessFile dst = new RandomAccessFile(mm,"rw");src.seek(0);for(int i=0;i<src.length();i++){int tmp=src.read();tmp-=5;dst.write(tmp);}src.close();dst.close();}
}

《Java语言程序设计与数据结构》编程练习答案(第十七章)相关推荐

  1. 《Java语言程序设计与数据结构》编程练习答案(第七章)(一)

    <Java语言程序设计与数据结构>编程练习答案(第七章)(一) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  2. 《Java语言程序设计与数据结构》编程练习答案(第三章)(三)

    <Java语言程序设计与数据结构>编程练习答案(第三章)(三) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  3. 《Java语言程序设计与数据结构》编程练习答案(第四章)(二)

    <Java语言程序设计与数据结构>编程练习答案(第四章)(二) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  4. 《Java语言程序设计与数据结构》编程练习答案(第四章)(一)

    <Java语言程序设计与数据结构>编程练习答案(第四章)(一) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  5. 《Java语言程序设计与数据结构》编程练习答案(第二章)(二)

    <Java语言程序设计与数据结构>编程练习答案(第二章)(二) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  6. java考试安徽工业大学_2011~2012《Java语言程序设计》试卷A及答案(安徽工业大学)...

    <2011~2012<Java语言程序设计>试卷A及答案(安徽工业大学)>由会员分享,可在线阅读,更多相关<2011~2012<Java语言程序设计>试卷A及 ...

  7. 南开大学java考试试题_2014秋学期南开大学《Java语言程序设计》在线作业附答案...

    2014秋学期南开大学<Java语言程序设计>在线作业附答案 1.下列代码中,将引起一个编译错误的行是(D). 1)public class Test{ 2) int m,n; 3) pu ...

  8. 自考04747《java语言程序设计(一)》课件_自考04747《java语言程序设计(一)》课后习题答案全集...

    <自考04747<java语言程序设计(一)>课后习题答案全集>由会员分享,可在线阅读,更多相关<自考04747<java语言程序设计(一)>课后习题答案全集 ...

  9. java语言程序设计期末考试试题及答案_《JAVA语言程序设计》期末考试试题及答案1-7.doc...

    <JAVA语言程序设计>期末考试试题及答案1-7 社望斡工耪纱访肝讫否稗仗族锯滥祥缀疏霹辐螟丁哥联退控罐绳屑铸氛券误滚烫周瞎鲸明垢礁蛀撞瓶蔬辗撞往件沽囊炕蔫消辉孽层束沁吨减攻匿少纳涡唆晚亦 ...

  10. (1 24) 3 java代码_《Java语言程序设计》测试题及参考答案(第1部分)

    一.单项选择题 1.Java Applet编程时用户的Applet程序类的正确定义是哪一种 ? (1)class MyApplet extends applet{ } (2)class MyApple ...

最新文章

  1. cmake 离线安装mysql_(cmake)编译安装mysql
  2. BZOJ 3173: [Tjoi2013]最长上升子序列
  3. Android 切换卡(TabWidget)
  4. leetcode题解153-寻找旋转排序数组的最小值
  5. 高中计算机网络功能,高中生自我教育中如何发挥计算机网络信息的作用
  6. curl 使用 ~/.netrc ( Windows 上是 _netrc ) 问题
  7. centos6.5系统bash损坏之救援模式修复
  8. itx机箱尺寸_itx主机还需要显卡吗?极限尺寸s18 itx机箱装机示范
  9. Windows明文密码获取
  10. python制作APP,此APP可识别TEM图片结构轮廓,并将坐标提取到excel中,画出TEM结构轮廓图(tkinter,opencv-python)
  11. Enterprise Architect 类关系对应解析
  12. Python 科研风格字体(中文宋体、英文新罗马)
  13. linux使用及shell常用命令技巧
  14. python对数正态分布函数_python中的对数正态分布
  15. GAMES101课程学习笔记—Lec 02:Linear Algebra 线性代数回顾
  16. Java面向对象基础练习
  17. 危化品厂区监控人脸识别/危化品识别EasyGBS+智能分析网关设备助力化工厂区安全生产
  18. [leetcode/lintcode 题解] 谷歌面试题:基因相似度
  19. 怎么确保数据在网络传输的安全性?
  20. Windows 10配置阿里云DNS

热门文章

  1. 泛型指针,原生指针和智能指针
  2. 2019全国地图数据下载-高德腾讯百度地图
  3. 飞机大战(微信小游戏)
  4. UEditor 百度Web编辑器 - JSP版本的使用
  5. 计算机网络与通信之物理层中的数据传输
  6. 计算机二级准考证下载打不开
  7. python写网页flash游戏辅助_会玩 | 使用 Python + Selenium制作Flash游戏辅助
  8. Android优秀参考APP源码
  9. mysql怎么设主键和外键_MySQL添加主键和外键
  10. 如何避免出现SQL注入漏洞