How to accept a space separated integer

This is a beginner question but still i have problem while dealing with it.
for e.g , After T no. of cases,
i have to enter K N for each case
which are space separated integers.
How to do it?

1 Like

In C, you can simply use

scanf("%d%d", &K, &N);


scanf("%d %d", &K, &N);


scanf("%d", &K);
scanf("%d", &N);

In C++, you can use

cin >> K >> N;

In Java, you can use

import java.util.StringTokenizer;
BufferedReader br = new BufferedReader(new InputStreamReader(;
StringTokenizer st = new StringTokenizer(br.readLine());
int K = Integer.parseInt(st.nextToken());
int N= Integer.parseInt(st.nextToken());

In Python, you can use

[K, N] = [int(i) for i in raw_input().split()]


K = input()
N = input()
1 Like


scanf("%d %d",&K,&N);

Java :- br = new;


String s=(br.readLine()).split(" ");

int K=Integer.parseInt(s[0]);

int N=Integer.parseInt(s[1];

If Input is not very large which is normally the case,you can directly use Scanner to read the inputs.

Scanner sc=new Scanner(;

Now suppose you pass the input as

5 1 2 3 4 5

Now to take this input just keep on doing sc.nextInt()/sc.nextLong() and you will get the desired element from the input in your program.

if you are using java use split fn;

BufferedReader br = new BufferedReader(new InputStreamReader(;
String str = br.readLine();
String[] arr = str.split("\\s+");

values will be stored in array arr.

In Python:

n,k = map(int,raw_input().split);
1 Like

how many times will you be asking questions
dont ask such silly questions after this
i will ask you a question try to answer it
who taught you to program

Hi, this is a platform to learn. We learn by asking what we do not know, don’t we? So, what is the problem in asking, irrespective of the question being silly (in the eyes of someone else)?

1 Like

It is

input_numbers = map(int,raw_input().split());

you have to call a function with () even though arguements are not needed in python unlike ruby

somebody please upvote me , i have questions to ask
thank you