しかも丁寧に使い方が書かれている
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)");
どこかから"(320,400)"みたいな文字列を取得して、それを解析したいときに使うなら・・・ new Point("(320,400)")?テストコードでしょ(笑)
これはPerlから来た人だな。リファレンスの使い方がわかってないと、こうするしか構造体が作れない