CodeX-API icon indicating copy to clipboard operation
CodeX-API copied to clipboard

Working with multiple input

Open BanDroid opened this issue 3 years ago • 5 comments

Is there a way to work with multiple input? For example the code is java, and asking twice for getting input from users.

BanDroid avatar Dec 31 '22 17:12 BanDroid

You can send multiple inputs within the same string sent as input but separated by a new line feed \n, here's how the curl request would then look like.

curl --location --request POST 'https://api.codex.jaagrav.in' \
--header 'Content-Type: application/json' \
--data-raw '{
    "code": "import java.util.Scanner;public class MatSym {public static void main(String[]args) {Scanner in = new Scanner(System.in);System.out.println(in.nextLine());System.out.println(in.nextLine());}}",
    "language": "java",
    "input": "Hello\nWorld"
}'

Import this on postman, make the request and you'll see the following response.

{
    "timeStamp": 1672522998106,
    "status": 200,
    "output": "Hello\nWorld\n",
    "error": "",
    "language": "java",
    "info": "openjdk 11.0.17 2022-10-18\nOpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu218.04)\nOpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu218.04, mixed mode, sharing)\n"
}

Please close this issue if your question is answered.

Jaagrav avatar Dec 31 '22 22:12 Jaagrav

Thank you, this answer my question.

BanDroid avatar Jan 01 '23 00:01 BanDroid

Hi @Jaagrav , i will re-open this issue again, there's issue with multiple inputs in static type language (such as java, c, c++, c#, etc).

If the code ask for multiple input that is not a string/character type, it will thrown error of type mismatch exception.

In your java example above, it ask for 2 string input. If you change to ask for int or other types, it will thrown error.

BanDroid avatar Jan 01 '23 12:01 BanDroid

Maybe the input body should be changed into array instead of string and using \n for separating input.

BanDroid avatar Jan 01 '23 12:01 BanDroid

I figure it out, multiple input for numbers are separated by whitespace, but strings by newline. Should i close this issue? Maybe this could be unexpected bugs you didn't know

BanDroid avatar Jan 01 '23 18:01 BanDroid