gpt4 book ai didi

Java:我如何获得我需要的int???用什么东西来分​​裂它们?

转载 作者:行者123 更新时间:2023-11-30 04:02:28 24 4
gpt4 key购买 nike

int x1;
int y1;
int x2;
int y2;

String shape = " sequenceNumber <Square> 50 60 70 90 </Square> "

public splitThem(String s){

//I can't figure out how to extract the information i need...
//... Do sometthing to extract splitThem(shape)
int this.x1 = parseString("50");
int this.y1 = parseString("60");
int this.x2 = parseString("70");
int this.y2 = parseString("90");

}

public void Graphics(graphic g){
g.drawRect(x1,y1,x2,y2);
}

我想知道是否有一种方法可以提取我需要的信息并将它们解析为整数???类似于 split 方法??

最佳答案

您可以使用Scanner扫描该字符串,并使用nextInt()您可以掌握整数值。

String s = " sequenceNumber <Square> 50 60 70 90 </Square> ";
Scanner scanner = new Scanner(s);
List<Integer> list = new ArrayList<Integer>();

while (scanner.hasNext()) {
if (scanner.hasNextInt()) {
list.add(scanner.nextInt());
}
else {
scanner.next();
}
}

执行上述代码后,您可以使用整数列表中的值设置形状坐标。

关于Java:我如何获得我需要的int???用什么东西来分​​裂它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21642170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com