开发者

Reading integers from a line

I'm trying to read two integers on the same line.

Scanner a=new Scanner(System.in);
x=a.nextInt();
y=a.nextInt();
开发者_JS百科

Now, if I input

3 4

3 4

x = 3 and y = 3. I even tried using a.useDelimiter("\\s") but it doesn't work.


There must be an error elsewhere in your code. It works fine for me.

import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner a = new Scanner(System.in);
        int x = a.nextInt();
        int y = a.nextInt();
        System.out.println("x = " + x + ", y = " + y);
    }
}

Input:

3 4
3 4

Output:

x = 3, y = 4

See it working online: ideone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜