java编程思想课后答案

更新时间:2023-07-13 12:20:00 阅读: 评论:0

java编程思想课后答案
【篇一:java编程思想第六章习题答案】
ava
tkd
// tij4 chapter arrays, exerci 10, page 762beef什么意思
// modify arrayofgeneric.java to u containers instead of arrays.
// show that you can eliminate the compile-time warnings.
import java.util.*;
  public class arrayofgenerics10 {
  }
  // arrays/containercomparison15.java
// tij4 chapter arrays, exerci 15, page 775
// modify containercomparison.java by creating a generator for
// berylliumsphere, and change main() to u that generator
// with generated.array().
import net.mindview.util.*;
import java.util.*;
import static net.mindview.util.print.*;
  class berylliumspheregenerator implements generatorberylliumsphere {
  }
public berylliumsphere next() {  return new berylliumsphere(); }@suppresswarnings(unchecked) public static void main(string[] args) { } listliststring lls = new arraylistliststring(); listlist l = new arraylistlist();  // lls = (listlis
tstring)l; // error: inconvertible types lls.add(new arrayliststring()); listobject lo = new arraylistobject(); // lo = lls; // error: incompatible types // compile-time warning eliminated: listlistberylliumsphere llb =new arraylistlistberylliumsphere(); for(int i = 0; i  10; i++) {llb.add(new arraylistberylliumsphere());  for(int j = 0; j  2; j++) (i).add(new berylliumsphere()); } system.out.println(llb);
public class containercomparison15 {
  }
  // reusing/sterilizer.java
// tij4 chapter reusing, exerci 2, page 243
proudof>江畔独步寻花其六 /* inherit a new class from class detergent. override scrub() and add a new method * called sterilize().
*/
import ls.print.*;
  public class sterilizer extends detergent {
  }
  // arrays/testarraygeneration16.java
// tij4 chapter arrays, exerci 16, page 775
/* starting with countinggenerator.java, create a skipgenerator class public void scrub() { append( sterilizer.scrub()); } public void sterilize() { append( sterilize()); } public static void main(string[] args) {  sterilizer x = new sterilizer();  x.dilute();  } x.apply();  x.scrub(); x.foam(); x.sterilize(); println(x); println(testing ba class:); detergent.main(args); public static void main(string[] args) {  berylliumsphere[] spheres = new berylliumsphere[5];  berylliumspheregenerator bsg = new berylliumspheregenerator();  generated.array(spheres, bsg);} string(spheres)); print(spheres[4]); listberylliumsphere spherelist = 
new arraylistberylliumsphere(); for(int i = 0; i  5; i++)  spherelist.()); print(spherelist); (4));
* that produces new values by incrementing according to a constructor  * argument. modify testarraygeneration.java to show that your new  * class works correctly.
*/
  import java.util.*;
import net.mindview.util.*;
import static net.mindview.util.print.*;
  public class testarraygeneration16 {
  } public static void main(string[] args) {} int size = 6; int skip = 7; boolean[] a1 = convertto.primitive(generated16.array(  new boolean[size], new skipgenerator16.bo
olean(skip), skip)); print(a1 =  + string(a1)); byte[] a2 = convertto.primitive(generated16.array(  new byte[size], new skipgenerator16.byte(skip), skip)); print(a2 =  + string(a2)); char[] a3 = convertto.primitive(generated16.array(  new character[size], new skipgenerator16.character(skip), skip)); print(a3 =  + string(a3)); short[] a4 = convertto.primitive(generated16.array(  new short[size], new skipgenerator16.short(skip), skip)); print(a4 =  + string(a4)); int[] a5 = convertto.primitive(generated16.array(  new integer[size], new skipgenerator16.integer(skip), skip)); print(a5 =  + string(a5)); long[] a6 = convertto.primitive(generated16.array(  new long[size], new skipgenerator16.long(skip), skip)); print(a6 =  + string(a6)); float[] a7 = convertto.primitive(generated16.array(  new float[size], new skipgenerator16.float(skip), skip)); print(a7 =  + string(a7)); double[] a8 = convertto.primitive(generated16.array(  new double[size], new skipgenerator16.double(skip), skip)); print(a8 =  + string(a8));
  // solution includes, in same package:
  /***************************
import net.mindview.util.*;
4级听力 interface skipgeneratort extends net.atort {t next();
t next(int n);
}
  public class skipgenerator16 {
public static class
boolean implements skipgeneratorjava.lang.boolean {  private boolean value = fal;
  private int n; boolean(int n) { this.n = n; }
public java.lang.boolean next() { return !value; }
public java.lang.boolean next(int n) {
value = n % 2 == 0 ? true : fal;
return value;
}
}
public static class
byte implements skipgeneratorjava.lang.byte {
private byte value = 0;内库
private int n;
byte(int n) { this.n = n; }
public java.lang.byte next() { return value++; }
public java.lang.byte next(int n) { return value += n; }
}
static char[] chars = (abcdefghijklmnopqrstuvwxyz +
abcdefghijklmnopqrstuvwxyz).tochararray();
西点烘焙培训班 public static class
character implements skipgeneratorjava.lang.character {  int index = -1;
private int n;
  character() { int index = -1; } character(int n) { this.n = n; }
public java.lang.character next() {
index = (index + 1) % chars.length;
return chars[index];
汉办网
}
public java.lang.character next(int n) {西安培华学院地址
index = (index + 1 + n) % chars.length;
return chars[index];
}
}
public static class
string implements skipgeneratorjava.lang.string {  private int length = 7;
skipgeneratorjava.lang.character cg = new character();  public string() {}
public string(int length) { this.length = length; }  public java.lang.string next() {
trivial char[] buf = new char[length];
for(int i = 0; i  length; i++)
buf[i] = cg.next();
return new java.lang.string(buf);
}
  public java.lang.string next(int n) {  char[] buf = new char[length]; for(int i = 0; i  length; i++)  buf[i] = cg.next(n); return new java.lang.string(buf);

本文发布于:2023-07-13 12:20:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/176115.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:编程   答案   思想   西安
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图