吴裕雄--天生自然 JAVA开发学习:多态
摘要:Parent p = new Child(); public class Test { public static void main(String[] args) { show(new Cat()); // 以 Cat 对象调用 show 方法 show(new Dog()); // 以 Dog 对象调用 show 方法 ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:重写(Override)与重载(Overload)
摘要:class Animal{ public void move(){ System.out.println("动物可以移动"); } } class Dog extends Animal{ public void move(){ System.out.println("狗可以跑和走"); } } public class TestDog{ ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:继承
摘要:class 父类 { } class 子类 extends 父类 { } public class Penguin { private String name; private int id; public Penguin(String myName, int myid) { name = myName; id = my...
阅读全文
吴裕雄--天生自然 JAVA开发学习:异常处理
摘要:try { // 程序代码 }catch(ExceptionName e1) { //Catch 块 } import java.io.*; public class ExcepTest{ public static void main(String args[]){ try{ int a[] = new int[2]; ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:Scanner 类
摘要:import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // 从键盘接收数据 // next方式接收字符串 ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:流(Stream)、文件(File)和IO
摘要:BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //使用 BufferedReader 在控制台读取字符 import java.io.*; public class BRRead { public static void main...
阅读全文
吴裕雄--天生自然 JAVA开发学习:方法
摘要:/** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) result = num1; else result = num2; return result; } public class TestMax { ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:正则表达式
摘要:import java.util.regex.*; class RegexExample1{ public static void main(String args[]){ String content = "I am noob " + "from runoob.com."; String pattern = ".*runoob.*"; ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:日期时间
摘要:import java.util.Date; public class DateDemo { public static void main(String args[]) { // 初始化 Date 对象 Date date = new Date(); // 使用 toString() 函数显示日期时间 Sys...
阅读全文
吴裕雄--天生自然 JAVA开发学习:StringBuffer、数组
摘要:public class Test{ public static void main(String args[]){ StringBuffer sBuffer = new StringBuffer("菜鸟教程官网:"); sBuffer.append("www"); sBuffer.append(".runoob"); sBuffer.append(".com...
阅读全文
吴裕雄--天生自然 JAVA开发学习:String 类
摘要:public class StringDemo{ public static void main(String args[]){ char[] helloArray = { 'r', 'u', 'n', 'o', 'o', 'b'}; String helloString = new String(helloArray); System.out.pr...
阅读全文
吴裕雄--天生自然 JAVA开发学习:Character 类
摘要:char ch = 'a'; // Unicode 字符表示形式 char uniChar = '\u039A'; // 字符数组 char[] charArray ={ 'a', 'b', 'c', 'd', 'e' }; public class Test { public static void main(String args[]) { Syste...
阅读全文
吴裕雄--天生自然 JAVA开发学习:Number & Math 类
摘要:int a = 5000; float b = 13.65f; byte c = 0x4a; public class Test{ public static void main(String args[]){ Integer x = 5; x = x + 10; System.out.println(x); } } public ...
阅读全文
吴裕雄--天生自然 JAVA开发学习:switch case 语句
摘要:public class Test { public static void main(String args[]){ //char grade = args[0].charAt(0); char grade = 'C'; switch(grade) { case 'A' : System.out...
阅读全文
吴裕雄--天生自然 JAVA开发学习:条件语句
摘要:public class Test { public static void main(String args[]){ int x = 10; if( x < 20 ){ System.out.print("这是 if 语句"); } } } if(布尔表达式){ //如果布尔表达式的值为true }else{ ...
阅读全文
吴裕雄--天生自然 JAVA开发学习: 循环结构
摘要:public class Test { public static void main(String args[]) { int x = 10; while( x < 20 ) { System.out.print("value of x : " + x ); x++; System.out.print("\n"...
阅读全文
吴裕雄--天生自然 JAVA开发学习:运算符
摘要:public class Test { public static void main(String[] args) { int a = 10; int b = 20; int c = 25; int d = 25; System.out.println("a + b = " + (a + b) ); System.out.pr...
阅读全文
吴裕雄--天生自然 JAVA开发学习:修饰符
摘要:public class InstanceCounter { private static int numInstances = 0; protected static int getCount() { return numInstances; } private static void addInstance() { numInstances...
阅读全文
吴裕雄--天生自然 JAVA开发学习:变量类型
摘要:public class Variable{ static int allClicks=0; // 类变量 String str="hello world"; // 实例变量 public void method(){ int i =0; // 局部变量 } } public class Test{ publi...
阅读全文
吴裕雄--天生自然 JAVA开发学习:基本数据类型
摘要:public class PrimitiveTypeTest { public static void main(String[] args) { // byte System.out.println("基本类型:byte 二进制位数:" + Byte.SIZE); System.out.println("包装类:java....
阅读全文