1、 /m.scream(); public static void main(String args) /int i; System.out.println(furColor); Dog d = new Dog(); Mouse m = new Mouse(); d.catchMouse(m); HelloWorld hw = new HelloWorld();class Mouse int height;Count3Quit.javapublic class Count3Quit int a = new int500; for(int i=0; ia.length; i+) ai = 1; i
2、nt leftCount = 500; int countNum = 0; int index = 0; while(leftCount != 1) if(aindex = 1) countNum +; if(countNum = 3) countNum = 0; aindex = 0; leftCount -; index +; if(index = a.length) index = 0; if(ai = 1) System.out.println(i);Fab.javapublic class Fab System.out.println(f(-9); public static lon
3、g f(int index) if(index 1) System.out.println(invalid parameter! return -1; if(index = 1 | index = 2) return 1; long f1 = 1L; long f2 = 1L; long f = 0;index-2; f = f1 + f2; f1 = f2; f2 = f; return f;HelloWorld.javapublic class HelloWorld static int j = 9; public static void main(String asdfasf) /a;s
4、ldfkja;sdjf;asjdf;asjdf System.out.println(HW System.out.println(123); System.out.println(j); int i = 8; public static void m() class TT ListFile.javaimport java.io.*;public class ListFile File f = new File(d:test /* File files = f.listFiles(); for(File ff : files) System.out.println(ff.getName(); *
5、/ listChilds(f, 0); public static void listChilds(File f, int level) String preStr = ;level; i+) preStr += System.out.println(preStr + f.getName(); if(!f.isDirectory() return; File childs = f.listFiles();childs.length; listChilds(childsi, level + 1);MySearch.javapublic class MySearch public class ma
6、in(String args) int a = 2, 5, 99, 4, 6, 8, 7, 24, 12; int m = 6; if(ai = m) OddSum.javapublic class OddSum long result = 0; for(int i=1;=99; i+=2) result += i; result= + result);Point3D.javapublic class Point3D double x, y, z; public Point3D(double _x, double _y, double _z) x = _x; y = _y; z = _z; p
7、ublic void setX(double _x) public double distance() return x*x + y*y + z*z; Point3D p = new Point3D(1.2, 3.4, 5.8); p.setX(1.3); System.out.println(p.distance();TestAccess.javaT.javapublic class T int i; void m(int i) this.i = i; void m(short i) short this.i = 8; T t = new T(); t.m(5);TestBreak.java
8、public class TestBreak public static void main(String args) int stop = 4; for (int i = 1; i radius * radius) return false; else return true; public void setO(double x, double y) o.setX(x); o.setY(y); public Point getO() return o; public double getRadius() return radius; public void setRadius(double
9、r) radius = r; public double area() return 3.14 * radius * radius;public class TestCircle Circle c1 = new Circle(new Point(1.0,2.0), 2.0); Circle c2 = new Circle(5.0);c1:(+c1.getO().getX()+, +c1.getO().getY()+),+c1.getRadius();c2:+c2.getO().getX() +c2.getO().getY()+c2.getRadius();c1 area = +c1.area(
10、);+c2.area(); c1.setO(5,6); c2.setRadius(9.0);+c2.getO().getX()+ +c2.getO().getY()+ Point p1 = new Point(5.2, 6.3); System.out.println(c1.contains(p1); System.out.println(c1.contains(new Point(10.0,9.0);TestConstruct.javaclass Person2 private String location; Person2(String name) location = beijing
11、Person2(String name,String location) this.location = location; public String info() return name: location:+location;class Teacher extends Person2 private String capital; Teacher(String name, String capital) this(name, , capital); Teacher(String name, String location, String capital) super(name, loca
12、tion); this.capital = capital; return super.info() + capital: + capital;public class TestConstruct Teacher t = new Teacher(B, GG System.out.println(t.info();TestConvert2.javapublic class TestConvert2 int i=1,j=12; float f1=(float)0.1; /0.1f float f2=123; long l1 = 12345678,l2=8888888888L; double d1
13、= 2e20,d2=124; byte b1 = 1,b2 = 2,b3 = 127; j = j+10; i = i/10; i = (int)(i*0.1); char c1=a,c2=125; byte b = (byte)(b1-b2); char c = (char)(c1+c2-1); float f3 = f1+f2; float f4 = (float)(f1+f2*0.1); double d = d1*i+j; float f = (float)(d1*5+d2);TestConvert.javapublic class TestConvert public static
14、void main(String arg) int i1 = 123; int i2 = 456; double d1 = (i1+i2)*1.2;/系统将转换为double型运算 float f1 = (float)(i1+i2)*1.2);/需要加强制转换符 byte b1 = 67; byte b2 = 89; byte b3 = (byte)(b1+b2);/系统将转换为int型运算,需要强制转换符 System.out.println(b3); double d2 = 1e200; float f2 = (float)d2;/会产生溢出 System.out.println(f2);
15、 float f3 = 1.23f;/必须加f long l1 = 123; long l2 = 30000000000L;/必须加l float f = l1+l2+f3;/系统将转换为float型计算 long l = (long)f;/强制转换会舍去小数部分(不是四舍五入)TestDigitCount.javapublic class TestDigitCount int i = 34789; double d = 3478.9765; digitCount2(String.valueOf(i); digitCount2(String.valueOf(d); public static
16、void digitCount(String s) int index = s.indexOf(. if(index = -1) System.out.println(s.length(); else 整数: + index + n + 小数: + (s.length() - index - 1); public static void digitCount2(String s) String s1 = s.replace(., , String ss = s1.split( if(ss.length = 1) System.out.println(s1.length(); else if(s
17、s.length = 2) + ss0.length() + + ss1.length();Format Error!TestEqual.javapublic class TestEqual Integer i1 = new Integer(1); Integer i2 = new Integer(1); System.out.println(i1 = i2); System.out.println(i1.equals(i2); Mao m1 = new Mao(A Mao m2 = new Mao( System.out.println(m1 = m2); System.out.printl
18、n(m1.equals(m2);class Mao String name; String color; Mao(String n,String c) name = n; color = c; public boolean equals(Object obj) return true;TestFormat.javapublic class TestFormat public static viod main(String args) okhello int i = 8 + 9;10; System.out.println(i); public void m() public void m2() public void m3() public void m4() TestIF.javapublic class TestIF int i = 20; if(i 20) 20 else if (i =60TestInherit.javaclass FatherClass publ
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1