0
String value = "30/90"
// Extracting 30 to a and 90 to b 
int a = 30;
int b = 90

如上例所示,如何提取“30”和“90”。所以斜线将指示“a”和“b”的位置。

4

2 回答 2

6

使用String#Split("/"):分割字符串/作为分隔符:

            String value = "30/90";
            int a = Integer.parseint(value.split("/")[0]);
            int b= Integer.parseInt(value.split("/")[1]);
于 2012-12-04T23:51:36.310 回答
0

试试这个:用/s 分割字符串并将生成的字符串解析为整数。

public class Main
{
    public static void main (String[] args)
    {
        String value = "30/90";
        // Extracting 30 to a and 90 to b 
        String[] values = value.split("/");
        int a = Integer.parseInt(values[0]);
        int b = Integer.parseInt(values[1]);
        System.out.println(a + " " + b);
    }
}
于 2012-12-04T23:52:21.107 回答