Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with multiple input #26

Open
BanDroid opened this issue Dec 31, 2022 · 5 comments
Open

Working with multiple input #26

BanDroid opened this issue Dec 31, 2022 · 5 comments

Comments

@BanDroid
Copy link

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

@Jaagrav
Copy link
Owner

Jaagrav commented Dec 31, 2022

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.

@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

Thank you, this answer my question.

@BanDroid BanDroid closed this as completed Jan 1, 2023
@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

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 BanDroid reopened this Jan 1, 2023
@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

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

@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants