成员方法
public class juxing { juxing(){ chang=1; kuan=1; } double chang; double kuan; double mianji(){ return (chang*kuan); } public static void mian(String []ages){ juxing a=new juxing(); a.chang=3.2; a.kuan=2.4; System.out.println("呵呵哒"+a.mianji()); } }
public static void main(String[] args) { // TODO 自动生成的方法存根 juxing a=new juxing(); System.out.println(a.mianji()); a.chang=3.2; a.kuan=2; System.out.println(a.mianji()); }
public class 运算 { double 数字一; double 数字二; double a2; void 运算方式 (String a){ switch(a){ case "加": a2=数字一+数字二; System.out.println(a2); break; case "+": a2=数字一+数字二; System.out.println(a2); break; case "-": a2=数字一-数字二; System.out.println(a2); break; case "减": a2=数字一-数字二; System.out.println(a2); break; case "*": a2=数字一-数字二; System.out.println(a2); break; case "乘": a2=数字一*数字二; System.out.println(a2); break; case "/": a2=数字一-数字二; System.out.println(a2); break; case "除": a2=数字一/数字二; System.out.println(a2); break; case "%": a2=数字一%数字二; System.out.println(a2); break; case "摩": a2=数字一-数字二; System.out.println(a2); break; default : System.out.println("别逗好么,我问你你怎么算"); } }
public static void main(String[] args) { // TODO 自动生成的方法存根 运算 a=new 运算(); a.数字一=10.2; a.数字二=3.3; a.运算方式("/");