博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
《Java语言程序设计与数据结构》编程练习答案(第十七章)
阅读量:4169 次
发布时间:2019-05-26

本文共 4591 字,大约阅读时间需要 15 分钟。

《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

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

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

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

👨不写了,全书完

转载地址:http://auwai.baihongyu.com/

你可能感兴趣的文章
12月英语--Sowing
查看>>
泛型--datatable TO List
查看>>
存储过程
查看>>
C#之导出excel
查看>>
版本控制--SVN
查看>>
泛型 VS Data Table
查看>>
CSS盒子模型
查看>>
HTML总结(一)
查看>>
3月英语--平平淡淡
查看>>
csf格式转换--逼自己一把
查看>>
ASP控件总结(一)
查看>>
Repeater&Validator控件使用
查看>>
细水翻起半点波涛--4月英语
查看>>
ASP--Active Server Pages Summary
查看>>
常见的电脑病毒
查看>>
站在巨人的肩膀上!
查看>>
2017年5月软考总结
查看>>
Node.js中运行JavaScript代码
查看>>
5月英语总结--I will do it well.
查看>>
认识JS
查看>>