开发者

Reading integers from a line

开发者 https://www.devze.com 2023-04-12 07:37 出处:网络
I\'mtrying to read two integers on the same line. Scanner a=new Scanner(System.in); x=a.nextInt(); y=a.nextInt();

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

精彩评论

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