如何在java中使用单独的两个整数?

问题描述:

我想打一个用户输入与圆点分隔像(11.56.98) 后,要使用整数x = 11 Y = 56,Z = 98如何在java中使用单独的两个整数?

`Scanner s = new Scanner(System.in); 
    System.out.print("Enter Your number like (36.52.10): "); 
    int x = s.nextInt(); 
    int y = s.nextInt(); 
    int z = s.nextInt();` 

现在怎么usedelimiter将变为空白,以点以及如何再次返回空白

+0

取值的字符串,然后除以值按乌尔要求 – Kick

+0

你能不能请澄清你想要做什么?你的最后一句话很难阅读,并且(至少对我而言)是不可能理解的。 – Mischa

+0

只需使用'string.split()'https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String) – Achilles

如果你想要在同一行使用:s.next()

如果你想在接下来的行中的文本,你需要做的:s.nextLine()

无论你采用什么方法,它会返回一个java.lang.String

您可以使用String[] numbers = yourString.split(".")

你会得到什么,如果你分割字符串你可以得到所有的数字数组:

int x = Integer.valueOf(numbers[0]); 
int y = Integer.valueOf(numbers[1]); 
int z = Integer.valueOf(numbers[2]); 
//Dont forget it can throw a NumberFormatException if the current String is not a valid number.