您可以使用nextLine方法读取字符串,并使用拆分方法将其以逗号分隔,如下所示:
public static void main(String args[]) { Scanner dis=new Scanner(System.in); int a,b,c; String line; String[] lineVector; line = dis.nextLine(); //read 1,2,3 //separate all values by comma lineVector = line.split(","); //parsing the values to Integer a=Integer.parseInt(lineVector[0]); b=Integer.parseInt(lineVector[1]); c=Integer.parseInt(lineVector[2]); System.out.println("a="+a); System.out.println("b="+b); System.out.println("c="+c); }此方法适用于仅用逗号分隔的3个值。
如果需要更改值的数量,可以使用循环从向量中获取值。



