2012-03-01から1ヶ月間の記事一覧
ifの終わりの中括弧”}”は次のelseにくっつける。 中括弧とelseを分けて(改行して)書かないほうがよい。 - if(条件式){}else{}
読み込み中...
class RecMethod{ int width; int height; RecMethod() { setSize(10, 20); } RecMethod(int w, int h) { setSize(w, h); } void setSize(int w, int h) { width = w; height = h; } int getArea() { return width * height; } }
class RecMain { public static void main(String[] args) { RecMethod r1 = new RecMethod(); System.out.println("r1.width = " + r1.width); System.out.println("r1.height = " + r1.height); System.out.println("r1.getArea() = " + r1.getArea()); Re…
class Rectangle { int width; int height; Rectangle() { setSize(10, 20); } Rectangle(int w, int h) { setSize(w, h); } void setSize(int w, int h) { width = w; height = h; } int getArea() { return width * height; } public static void main(Str…