import java.util.*;
import java.io.*;
/** *//**A class comment*/
public class Test
{
/**//*
public static void main(String[] args)
{
double i = 0;
while(i<0.99d)
{
i = Math.random();
System.out.println(i);
}
}*/
/**//*
public static void main(String[] args)
{
for(int i=0;i<128;i++)
if(Character.isLowerCase((char)i))
System.out.println("value:"+i+"char:"+(char)i);
}*/
/**//*
public static void main(String[] args)
{
for(int i=1,j=i+10;i<5;i++,j=i*2)
{
System.out.println("i="+i+"j="+j);
}
}*/
public static void main(String[] args)
{
//new BreakAndContinue();
//new LableFor();
//new SwitchTest();
/**//*
OverLoading ol = new OverLoading();
ol.testConstVal();
ol.testChar();
ol.testByte();
ol.testShort();
ol.testInt();
ol.testLong();
ol.testFloat();
ol.testDouble();*/
/**//*
ThisTest1 tt = new ThisTest1();
tt.increment().increment().increment().increment().print();*/
//ThisTest2 tt = new ThisTest2();
/**//*
Bath b = new Bath();
System.out.println(b);*/
/**//*
Detergent d = new Detergent();
d.dilute();d.apply();d.scrub();d.foam();
System.out.println(d);
System.out.println("Testing base class");*/
//Cartoon c = new Cartoon();
//Chess c = new Chess();
//PlaceSetting ps = new PlaceSetting(2);
//CADSystem cs = new CADSystem(8);
/**//*
Bart b = new Bart();
b.doh(1);
b.doh('x');
b.doh(1.0f);
b.doh(new Milhouse());*/
/**//*
Orc o = new Orc("bulktree",23);
System.out.println(o);
o.change("oakertree",22);
System.out.println(o);*/
//Beetle b = new Beetle();
/**//*
RandomShapeGenerator rsg = new RandomShapeGenerator();
Shape[] s = new Shape[9];
for(int i=0;i<s.length;i++)
s[i] = rsg.next();
for(int i=0;i<s.length;i++)
s[i].draw();*/
/**//*
Instrument[] i = new Instrument{
new Wind(),
new Percussion(),
new Stringed(),
new Brass(),
new WoodWind()
};*/
//new Sandwich();
/**//*
System.out.println(RandVals.randomInt);
System.out.println(RandVals.randomLong);
System.out.println(RandVals.randomFloat);
System.out.println(RandVals.randomDouble);*/
/**//*
A a = new A();
A a2 = new A();
a2.receiveD(a.getD());*/
/**//*
Parcel1 p = new Parcel1();
p.ship("xiangtan");
p.ship("湘潭");*/
/**//*
Parcel2 p = new Parcel2();
p.ship("湘潭");
Parcel2 q = new Parcel2();
Parcel2.Contents c = q.getContents();
Parcel2.Destination d = q.getDestination("南方");
d.readLabel();*/
/**//*
MNA mna = new MNA();
mna.f();
MNA.A mnaa = mna.new A();
mnaa.g();
MNA.A.B mnaab = mnaa.new B();
mnaab.h();*/
/**//*
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);*/
/**//*
Callee1 c1 = new Callee1();
Callee2 c2 = new Callee2();
MyIncrement.f(c2);
Caller caller1 = new Caller(c1);
Caller caller2 = new Caller(c2.getCallbackReference());
caller1.go();
caller1.go();
caller2.go();
caller2.go();*/
/**//*
try
{
ExtraFeatures.f();
}
catch(MyException e)
{
e.printStackTrace();
}
try
{
ExtraFeatures.g();
}
catch(MyException e)
{
e.printStackTrace();
}
try
{
ExtraFeatures.h();
}
catch(MyException e)
{
e.printStackTrace();
System.out.println("e.val()="+e.val());
}*/
//new ArraySize();
/**//*
new IceCream();
for(int i=0;i<20;i++)
System.out.println("flavorSet("+i+")=");
String[] f1 = flavorSet(flavors.length);
for(int j=0;j<fl.length;j++)
System.out.println("\t"+f1[j]);*/
/**//*
System.out.println(PrintCollection.fill(new ArrayList()));
System.out.println(PrintCollection.fill(new HashSet()));
System.out.println(PrintCollection.fill(new HashMap()));*/
//new FillingLists();
/**//*
List list = new ArrayList();
for(int i=0;i<3;i++)
{
list.add(new Hamster(i));
System.out.println(list.iterator().next());
}*/
//new SimpleCollection();
/**//*
try
{
new IOStreamDemo();
}
catch(IOException e)
{
e.printStackTrace();
}*/
try
{
new StreamTest();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
/**//*
class BreakAndContinue
{
BreakAndContinue()
{
for(int i=0;i<100;i++)
{
if(i==74)
break;
if(i%9!=0)
continue;
System.out.println("i="+i);
}
int i = 0;
while(true)
{
i++;
int j = i*27;
if(j==1269)
break;
if(i%10!=0)
continue;
System.out.println("i="+i);
}
}
}*/
/**//*
class LableFor
{
LableFor()
{
int i=0;
outer:
for(;true;)
{
inner:
for(;i<10;i++)
{
System.out.println("i="+i);
if(i==2)
{
System.out.println("continue");
continue;
}
if(i==3)
{
System.out.println("break");
i++;
break;
}
if(i==7)
{
System.out.println("continue outer");
i++;
continue outer;
}
if(i==8)
{
System.out.println("break outer");
break outer;
}
for(int k=0;k<5;k++)
{
if(k==3)
{
System.out.println("continue inner");
continue inner;
}
}
}
}
}
}*/
/**//*
class SwitchTest
{
SwitchTest()
{
for(int i=0;i<100;i++)
{
char c = (char)(Math.random()*26+'a');
System.out.println(c+":");
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("vowel");
break;
case 'y':
case 'w':
System.out.println("sometime a vowel");
break;
default:
System.out.println("consonant");
}
}
}
}*/
/**//*
class OverLoading
{
void f1(char x)
{
System.out.println("f1(char)");
}
void f1(byte x)
{
System.out.println("f1(byte)");
}
void f1(short x)
{
System.out.println("f1(short)");
}
void f1(int x)
{
System.out.println("f1(int)");
}
void f1(long x)
{
System.out.println("f1(long)");
}
void f1(float x)
{
System.out.println("f1(float)");
}
void f1(double x)
{
System.out.println("f1(double)");
}
void f2(byte x)
{
System.out.println("f1(byte)");
}
void f2(short x)
{
System.out.println("f1(short)");
}
void f2(int x)
{
System.out.println("f2(int)");
}
void f2(long x)
{
System.out.println("f2(long)");
}
void f2(float x)
{
System.out.println("f2(float)");
}
void f2(double x)
{
System.out.println("f2(double)");
}
void f3(short x)
{
System.out.println("f3(short)");
}
void f3(int x)
{
System.out.println("f3(int)");
}
void f3(long x)
{
System.out.println("f3(long)");
}
void f3(float x)
{
System.out.println("f3(float)");
}
void f3(double x)
{
System.out.println("f3(double)");
}
void f4(int x)
{
System.out.println("f4(int)");
}
void f4(long x)
{
System.out.println("f4(long)");
}
void f4(float x)
{
System.out.println("f4(float)");
}
void f4(double x)
{
System.out.println("f4(double)");
}
void f5(long x)
{
System.out.println("f5(long)");
}
void f5(float x)
{
System.out.println("f5(float)");
}
void f5(double x)
{
System.out.println("f5(double)");
}
void f6(float x)
{
System.out.println("f6(float)");
}
void f6(double x)
{
System.out.println("f6(double)");
}
void f7(double x)
{
System.out.println("f7(double)");
}
void testConstVal()
{
System.out.println("Test With 5");
f1(5);f2(5);f3(5);f4(5);f5(5);f6(5);f7(5);
}
void testChar()
{
char x='x';
System.out.println("char argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testByte()
{
byte x = 0;
System.out.println("byte argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testShort()
{
short x = 0;
System.out.println("short argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testInt()
{
int x = 0;
System.out.println("int argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testLong()
{
long x = 0;
System.out.println("long argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testFloat()
{
float x = 0;
System.out.println("float argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testDouble()
{
double x = 0;
System.out.println("double argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
}
*/
/**//*
class ThisTest1
{
int i = 0;
ThisTest1 increment()
{
i++;
return this;
}
void print()
{
System.out.println("i="+i);
}
}*/
/**//*
class ThisTest2
{
int count = 0;
String s = new String("null");
ThisTest2(int number)
{
count = number;
System.out.println("Constructor int arg only,count="+count);
}
ThisTest2(String ss)
{
s = ss;
System.out.println("Constructor String arg only,s="+s);
}
ThisTest2(String s,int number)
{
this(number);
this.s = s;
System.out.println("String & int args");
}
ThisTest2()
{
this("hi",47);
System.out.println("default constructor(no args)");
System.out.println("count="+count+" "+"s="+s);
}
}*/
/**//*
class Soap
{
private String s;
Soap()
{
System.out.println("Soap()");
s = new String("Constructed");
}
public String toString()
{
return s;
}
}
class Bath
{
private String s1 = new String("Happy"),
s2 = "Happy",s3,s4;
private Soap castille;
private int i;
private float toy;
public Bath()
{
System.out.println("Inside Bath()");
s3 = new String("Joy");
i = 47;
toy = 3.14f;
castille = new Soap();
}
public String toString()
{
if(s4==null)
s4 = new String("Joy");
return
"s1="+s1+"\n"+
"s2="+s2+"\n"+
"s3="+s3+"\n"+
"s4="+s4+"\n"+
"i="+i+"\n"+
"toy="+toy+"\n"+
"castille="+castille;
}
}*/
/**//*
class Cleanser
{
private String s = new String("Cleanser");
public void append(String a)
{
s += a;
}
public void dilute()
{
append("dilute()");
}
public void apply()
{
append("apply()");
}
public void scrub()
{
append("scrub()");
}
public String toString()
{
return s;
}
public static void main(String[] args)
{
Cleanser c = new Cleanser();
c.dilute();c.apply();c.scrub();
System.out.println(c);
}
}
class Detergent extends Cleanser
{
public void scrub()
{
append("Detergent.scrub()");
super.scrub();
}
public void foam()
{
append("foam()");
}
}*/
//默认构造函数
/**//*
class Art
{
Art()
{
System.out.println("Art Constructor");
}
}
class Drawing extends Art
{
Drawing()
{
System.out.println("Drawing Constructor");
}
}
class Cartoon extends Drawing
{
Cartoon()
{
System.out.println("Cartoon Constructor");
}
}*/
//带参数的构造函数
/**//*
class Game
{
Game()
{
System.out.println("default Constructor");
}
Game(int i)
{
System.out.println("Game Constructor");
}
}
class BoardGame extends Game
{
BoardGame(int i)
{
//super();
//super(4);
super(i);
System.out.println("BoardGame Constructor");
}
}
class Chess extends BoardGame
{
Chess()
{
super(3);
System.out.println("Chess Constructor");
}
}*/
//合成、继承
/**//*
class Plate
{
Plate(int i)
{
System.out.println("Plate Constructor");
}
}
class DinnerPlate extends Plate
{
DinnerPlate(int i)
{
super(i);
System.out.println("DinnerPlate Constructor");
}
}
class Utensil
{
Utensil(int i)
{
System.out.println("Utensil Constructor");
}
}
class Spoon extends Utensil
{
Spoon(int i)
{
super(i);
System.out.println("Spoon Constructor");
}
}
class Fork extends Utensil
{
Fork(int i)
{
super(i);
System.out.println("Fork Constructor");
}
}
class Knife extends Utensil
{
Knife(int i)
{
super(i);
System.out.println("Knife Constructor");
}
}
class Custom
{
Custom(int i)
{
System.out.println("Custom Constructor");
}
}
class PlaceSetting extends Custom
{
private Spoon sp;
private Fork fo;
private Knife kn;
private DinnerPlate dp;
PlaceSetting(int i)
{
//super(i);
super(i+1);
sp = new Spoon(i+2);
fo = new Fork(i+3);
kn = new Knife(i+4);
dp = new DinnerPlate(i+5);
System.out.println("PlaceSetting Constructor");
}
}*/
/**//*
class Shape
{
Shape(int i)
{
System.out.println("Shape Constructor");
}
void dispose()
{
System.out.println("Shape dispose");
}
}
class Circle extends Shape
{
Circle(int i)
{
super(i);
System.out.println("Drwing Circle");
}
void dispose()
{
System.out.println("Erasing Circle");
super.dispose();
}
}
class Triangle extends Shape
{
Triangle(int i)
{
super(i);
System.out.println("Triangle Constructor");
}
void dispose()
{
System.out.println("Erasing Triangle");
super.dispose();
}
}
class Line extends Shape
{
private int start,end;
Line(int start,int end)
{
super(start);
this.start = start;
this.end = end;
System.out.println("Drawing Line:"+start+","+end);
}
void dispose()
{
System.out.println("Erasing Line:"+start+","+end);
super.dispose();
}
}
class CADSystem extends Shape
{
private Circle c;
private Triangle t;
private Line[] lines = new Line[5];
CADSystem(int i)
{
super(i+1);
for(int j=0;j<lines.length;j++)
lines[j] = new Line(j,j*j);
c = new Circle(1);
t = new Triangle(1);
System.out.println("Combined Constructor");
}
void dispose()
{
System.out.println("CADSystem dispose()");
c.dispose();
t.dispose();
for(int i=lines.length-1;i>=0;i--)
lines[i].dispose();
}
}*/
//名字的覆盖
/**//*
class Homer
{
char doh(char c)
{
System.out.println("doh(char)");
return 'd';
}
float doh(float f)
{
System.out.println("doh(float)");
return 1.0f;
}
}
class Milhouse
{
}
class Bart extends Homer
{
void doh(Milhouse m)
{
System.out.println("doh(Milhouse)");
}
}*/
//protected关键字
/**//*
class Villain
{
private String name;
protected void set(String nm)
{
name = nm;
}
Villain(String name)
{
this.name = name;
}
public String toString()
{
return "I'm a Villain and My name is "+name;
}
}
class Orc extends Villain
{
private int orcNumber;
Orc(String name,int orcNumber)
{
super(name);
this.orcNumber = orcNumber;
}
public void change(String name,int orcNumber)
{
set(name);
this.orcNumber = orcNumber;
}
public String toString()
{
return "Orc"+orcNumber+":"+super.toString();
}
}*/
//继承情况下的初始化
/**//*
class Insect
{
private int i = 9;
protected int j;
Insect()
{
System.out.println("i="+i+","+"j="+j);
j = 324;
}
private static int x1 = print("static Insect.x1 initialized");
static int print(String s)
{
System.out.println(s);
return 23;
}
}
class Beetle extends Insect
{
private int k = print("Beetle.k initialized");
Beetle()
{
System.out.println("k="+k);
System.out.println("j="+j);
}
private static int x2 = print("static Beetle.x2 initialized");
}*/
//多态性
/**//*
class Shape
{
void draw()
{
}
void erase()
{
}
}
class Cricle extends Shape
{
void draw()
{
System.out.println("Cricle draw()");
}
void erase()
{
System.out.println("Cricle erase()");
}
}
class Square extends Shape
{
void draw()
{
System.out.println("Square draw()");
}
void erase()
{
System.out.println("Square erase()");
}
}
class Triangle extends Shape
{
void draw()
{
System.out.println("Triangle draw()");
}
void erase()
{
System.out.println("Triangle erase()");
}
}
class RandomShapeGenerator
{
private Random random = new Random();
public Shape next()
{
switch(random.nextInt(3))
{
default:
case 0: return new Cricle();
case 1: return new Square();
case 2: return new Triangle();
}
}
}*/
//可扩展性
/**//*
class Instrument
{
void play(Note n)
{
System.out.println("Instrument.play()"+n);
}
String what()
{
return "Instrument";
}
void adjust()
{
}
}
class Wind extends Instrument
{
void play(Note n)
{
System.out.println("Wind.play()"+n);
}
String what()
{
return "Wind";
}
void adjust()
{
}
}
class Percussion extends Instrument
{
void play(Note n)
{
System.out.println("Percussion.play()"+n);
}
String what()
{
return "Percussion";
}
void adjust()
{
}
}
class Stringed extends Instrument
{
void play(Note n)
{
System.out.println("Stringed.play()"+n);
}
String what()
{
return "Stringed";
}
void adjust()
{
}
}
class Brass extends Wind
{
void play(Note n)
{
System.out.println("Brass.play()"+n);
}
void adjust()
{
System.out.println("Brass.adjust()");
}
}
class WoodWind extends Wind
{
void play(Note n)
{
System.out.println("WoodWind.play()"+n);
}
String what()
{
return "WoondWind";
}
}*/
/**//*
class Meal
{
Meal()
{
System.out.println("Meal()");
}
}
class Bread
{
Bread()
{
System.out.println("Bread()");
}
}
class Cheese
{
Cheese()
{
System.out.println("Cheese()");
}
}
class Lettuce
{
Lettuce()
{
System.out.println("Lettuce()");
}
}
class Lunch extends Meal
{
Lunch()
{
System.out.println("Lunch()");
}
}
class PortableLunch extends Lunch
{
PortableLunch()
{
System.out.println("PortableLunch()");
}
}
class Sandwich extends PortableLunch
{
private Bread b = new Bread();
private Cheese c = new Cheese();
private Lettuce l = new Lettuce();
Sandwich()
{
System.out.println("Sandwich()");
}
}*/
//接口创建类
/**//*
interface CanFight
{
void fight();
}
interface CanSwim
{
void swim();
}
interface CanFly
{
void fly();
}
class ActionCharacter
{
public void fight()
{
System.out.println("fight()");
}
}
class Hello extends ActionCharacter implements CanFight,CanSwim,CanFly
{
public void swim()
{
System.out.println("swim()");
}
public void fly()
{
System.out.println("fly()");
}
}
class Adventure
{
public static void t(CanFight x)
{
x.fight();
}
public static void u(CanSwim x)
{
x.swim();
}
public static void v(CanFly x)
{
x.fly();
}
public static void w(ActionCharacter x)
{
x.fight();
}
public static void main(String[] args)
{
Hello h = new Hello();
t(h);
u(h);
v(h);
w(h);
}
}*/
//用继承扩展接口
/**//*
interface Monster
{
void menace();
}
interface DangerousMonster extends Monster
{
void destroy();
}
interface Lethal
{
void kill();
}
class DragonZilla implements DangerousMonster
{
public void menace()
{
}
public void destroy()
{
}
}
interface Vampire extends DangerousMonster,Lethal
{
void drinkBlood();
}
class VeryBadVampire implements Vampire
{
public void menace()
{
}
public void destroy()
{
}
public void kill()
{
}
public void drinkBlood()
{
}
}
class HorrorShow
{
public static void u(Monster x)
{
x.menace();
}
public static void v(DangerousMonster x)
{
x.menace();
x.destroy();
}
public static void w(Lethal x)
{
x.kill();
}
public static void main(String[] args)
{
DangerousMonster dm = new DragonZilla();
u(dm);
v(dm);
Vampire va = new VeryBadVampire();
u(va);
v(va);
w(va);
}
}*/
//接口数据成员初始化(默认static final)
/**//*
interface RandVals
{
Random rand = new Random();
int randomInt = rand.nextInt(10);
long randomLong = rand.nextLong()*10;
float randomFloat = rand.nextFloat()*10;
double randomDouble = rand.nextDouble()*10;
}*/
//接口的嵌套
/**//*
class A
{
interface B
{
void f();
}
public class BImp implements B
{
public void f()
{
}
}
private class BImp2 implements B
{
public void f()
{
}
}
public interface C
{
void f();
}
class CImp implements C
{
public void f()
{
}
}
private interface D
{
void f();
}
private class DImp implements D
{
public void f()
{
}
}
public class DImp2 implements D
{
public void f()
{
}
}
public D getD()
{
return new DImp2();
}
private D dRef;
public void receiveD(D d)
{
dRef = d;
dRef.f();
}
}
interface E
{
interface G
{
void f();
}
public interface H
{
void f();
}
void g();
}
class NestingInterfaces
{
public class BImp implements A.B
{
public void f()
{
}
}
class CImp implements A.C
{
public void f()
{
}
}
class EImp implements E
{
public void g()
{
}
}
class EGImp implements E.G
{
public void f()
{
}
}
class EImp2 implements E
{
public void g()
{
}
class EG implements E.G
{
public void f()
{
}
}
}
}*/
//内部类
/**//*
class Parcel1
{
class Contents
{
private int i = 11;
public int value()
{
return i;
}
}
class Destination
{
private String Label;
Destination(String whereTo)
{
Label = whereTo;
}
String readLabel()
{
return Label;
}
}
public void ship(String dest)
{
Contents c = new Contents();
Destination d = new Destination(dest);
System.out.println(d.readLabel());
}
}*/
/**//*
class Parcel2
{
class Contents
{
private int i = 11;
public int value()
{
return i;
}
}
class Destination
{
private String Label;
Destination(String whereTo)
{
Label = whereTo;
}
String readLabel()
{
return Label;
}
}
public Destination getDestination(String s)
{
return new Destination(s);
}
public Contents getContents()
{
return new Contents();
}
public void ship(String dest)
{
Contents c = new Contents();
Destination d = new Destination(dest);
System.out.println(d.readLabel());
}
}*/
/**//*
class MNA
{
void f()
{
System.out.println("mna.f()");
}
class A
{
void g()
{
System.out.println("mnaa.g()");
}
public class B
{
void h()
{
g();
f();
}
}
}
}*/
//继承内部类
/**//*
class WithInner
{
class Inner
{
}
}
class InheritInner extends WithInner.Inner
{
InheritInner(WithInner wi)
{
wi.super();
}
}*/
/**//*
interface Incrementable
{
void increment();
}
class Callee1 implements Incrementable
{
private int i = 0;
public void increment()
{
i++;
System.out.println(i);
}
}
class MyIncrement
{
void increment()
{
System.out.println("other operation");
}
static void f(MyIncrement mi)
{
mi.increment();
}
}
class Callee2 extends MyIncrement
{
private int i = 0;
private void incr()
{
i++;
System.out.println(i);
}
private class Closure implements Incrementable
{
public void increment()
{
incr();
}
}
Incrementable getCallbackReference()
{
return new Closure();
}
}
class Caller
{
private Incrementable callbackReference;
Caller(Incrementable cbh)
{
callbackReference = cbh;
}
void go()
{
callbackReference.increment();
}
}*/
//自定义异常
/**//*
class MyException extends Exception
{
private int x;
public MyException()
{
}
public MyException(String msg)
{
super(msg);
}
public MyException(String msg,int x)
{
super(msg);
this.x = x;
}
public int val()
{
return x;
}
public String getMessage()
{
return "Detail Message:"+x+" "+super.getMessage();
}
}
class ExtraFeatures
{
public static void f() throws MyException
{
System.out.println("throws MyException from f()");
throw new MyException();
}
public static void g() throws MyException
{
System.out.println("throws MyException from g()");
throw new MyException("Originated in g()");
}
public static void h() throws MyException
{
System.out.println("throws MyException from h()");
throw new MyException("Originated in h()",47);
}
}*/
//数组与对象
/**//*
class Weeble
{
}
class ArraySize
{
ArraySize()
{
Weeble[] a;
Weeble[] b = new Weeble[5];
Weeble[] c = new Weeble[4];
for(int i=0;i<c.length;i++)
if(c[i]==null)
c[i] = new Weeble();
Weeble[] d = {new Weeble(),new Weeble(),new Weeble()};
a = new Weeble[] {new Weeble(),new Weeble()};
System.out.println("a.length="+a.length);
System.out.println("b.length="+b.length);
for(int i=0;i<b.length;i++)
System.out.println("b["+i+"]="+b[i]);
System.out.println("c.length="+c.length);
System.out.println("d.length="+d.length);
a = d;
System.out.println("a.length="+a.length);
int[] e;
int[] f = new int[5];
int[] g = new int[4];
for(int i=0;i<g.length;i++)
g[i] = i*i;
int[] h = {11,47,93};
System.out.println("f.length="+f.length);
for(int i=0;i<f.length;i++)
System.out.println("f["+i+"]="+f[i]);
System.out.println("g.length="+g.length);
System.out.println("h.length="+h.length);
for(int i=0;i<h.length;i++)
System.out.println("h["+i+"]="+h[i]);
e = h;
System.out.println("e.length="+e.length);
e = new int[] {1,2};
System.out.println("e.length="+e.length);
}
}*/
//java容器类
/**//*
class PrintCollection
{
static Collection fill(Collection c)
{
c.add("dog");
c.add("dog");
c.add("cat");
c.add("hat");
return c;
}
static Map fill(Map m)
{
m.put("dog","Bosco");
m.put("dog","Spot");
m.put("cat","Rags");
m.put("hat","bulktree");
return m;
}
}*/
/**//*
class FillingLists
{
FillingLists()
{
List list = new ArrayList();
for(int i=0;i<10;i++)
list.add("");
Collections.fill(list,"Hello");
System.out.println(list);
}
}*/
/**//*
class Hamster
{
private int hamsterNumber;
public Hamster(int hamsterNumber)
{
this.hamsterNumber = hamsterNumber;
}
public String toString()
{
return "This is Hamster #"+hamsterNumber;
}
}*/
/**//*
class SimpleCollection
{
SimpleCollection()
{
Collection c = new ArrayList();
for(int i=0;i<10;i++)
c.add(Integer.toString(i));
Iterator it = c.iterator();
while(it.hasNext())
System.out.println(it.next());
}
}*/
/**//*
class IOStreamDemo
{
IOStreamDemo() throws IOException
{
BufferedReader in = new BufferedReader(new fileReader("IOStreamDemo.java"));
String s,s2 = new String();
while(s=in.readLine()!=null)
s2 = s2+s+"\n";
in.close();
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a line");
System.out.println(stdin.readLine());
StringReader in2 = new StringReader(s2);
int c;
while((c=in2.read())!=null)
System.out.println((char)c);
try
{
BufferedReader in4 = new BufferedReader(new StringReader(s2));
PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out")));
int lineCount = 1;
while((s = in4.readLine()) != null )
out1.println(lineCount++ + ": " + s);
out1.close();
}
catch(EOFException e)
{
System.err.println("End of stream");
}
try
{
DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt")));
out2.writeDouble(3.14159);
out2.writeUTF("That was pi");
out2.writeDouble(1.41413);
out2.writeUTF("Square root of 2");
out2.close();
DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt")));
System.out.println(in5.readDouble());
System.out.println(in5.readUTF());
System.out.println(in5.readDouble());
System.out.println(in5.readUTF());
}
catch(EOFException e)
{
throw new RuntimeException(e);
}
}
}*/
class StreamTest
{
StreamTest() throws IOException
{
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("Test.java")));
while(in.available()!=0)
System.out.print((char)in.readByte());
}
}
posted on 2007-12-27 16:45
凌晨风 阅读(440)
评论(0) 编辑 收藏 所属分类:
Java学习笔记