しかも丁寧に使い方が書かれている
class Rect { private int width; private int height; /** * コンストラクタ * @param str 例 "100x200" */ public Rect (String str) { String[] args = str.split("x"); width = Integer.parseInt(args[0]); height = Integer.parseInt(args[1]); } … } class Point { private int x; private int y; /** * コンストラクタ * @param str 例 "(100,200)" */ public Point (String str) { String substr = str.substring(1, str.length()-1); String[] args = substr.split(","); x = Integer.parseInt(args[0]); y = Integer.parseInt(args[1]); } … } Rect rectA = new Rect("320x480"); Rect rectB = new Rect("640x800"); Point pointA = new Point("(160,240)"); Point pointB = new Point("(320,400)");
使い方ヒント: 「これは臭う」という行を見付けたら、各行のをクリックしてマーキングしておきましょう(要Twitter OAuth認証)
どこかから"(320,400)"みたいな文字列を取得して、それを解析したいときに使うなら・・・ new Point("(320,400)")?テストコードでしょ(笑)
コメント投稿には、twitter認証が必要です。
Twitter認証
これはPerlから来た人だな。リファレンスの使い方がわかってないと、こうするしか構造体が作れない