javaVSCode icon indicating copy to clipboard operation
javaVSCode copied to clipboard

How can i use scanner in vscode ?

Open Estebjor opened this issue 8 years ago • 13 comments

I want to use a number from the keyboard, how can i configure VSCODE. ? ` import java.util.Scanner;

class Acceptinput{

public static void main (String[] args){
    int a;
    Scanner s = new Scanner (System.in);
    System.out.println("Enter your lucky number");
    a = s.nextInt();
    System.out.println("Your lucky number is: " +a);
}

} `

Estebjor avatar Aug 25 '17 06:08 Estebjor

use "externalConsole": true in your launch.json

On Fri, Aug 25, 2017 at 1:40 AM, Estebjor [email protected] wrote:

I want to use a number from the keyboard, how can i configure VSCODE. ? ` import java.util.Scanner;

class Acceptinput{

public static void main (String[] args){ int a; Scanner s = new Scanner (System.in); System.out.println("Enter your lucky number"); a = s.nextInt(); System.out.println("Your lucky number is: " +a); }

} `

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/67, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7NxwRO-n0QhADxA_tO0fdUpbXD434Pks5sbmxXgaJpZM4PCR8b .

faustinoaq avatar Aug 25 '17 10:08 faustinoaq

Actually it is true `{ "version": "0.2.0", "configurations": [

    {
        "name": "Java",
        "type": "java",
        "request": "launch",
        "stopOnEntry": true,
        "jdkPath": "${env:JAVA_HOME}/bin",
        "cwd": "${fileDirname}",
        "startupClass": "${fileBasenameNoExtension}",
        "classpath": [
            ".",
            "${fileDirname}"
        ]
    },
    {
        "name": "Java Console App",
        "type": "java",
        "request": "launch",
        "stopOnEntry": true,
        "jdkPath": "${env:JAVA_HOME}/bin",
        "cwd": "${fileDirname}",
        "startupClass": "${fileBasenameNoExtension}",
        "classpath": [
            ".",
            "${fileDirname}"
        ],
        "externalConsole": true
    }
]

}`

Estebjor avatar Aug 25 '17 15:08 Estebjor

Then, be sure that "Java Console App" is checked in debug menu before click the green play button. :-)

On Fri, Aug 25, 2017 at 10:01 AM, Estebjor [email protected] wrote:

Actually it is true `{ "version": "0.2.0", "configurations": [

{
    "name": "Java",
    "type": "java",
    "request": "launch",
    "stopOnEntry": true,
    "jdkPath": "${env:JAVA_HOME}/bin",
    "cwd": "${fileDirname}",
    "startupClass": "${fileBasenameNoExtension}",
    "classpath": [
        ".",
        "${fileDirname}"
    ]
},
{
    "name": "Java Console App",
    "type": "java",
    "request": "launch",
    "stopOnEntry": true,
    "jdkPath": "${env:JAVA_HOME}/bin",
    "cwd": "${fileDirname}",
    "startupClass": "${fileBasenameNoExtension}",
    "classpath": [
        ".",
        "${fileDirname}"
    ],
    "externalConsole": true
}

]

}`

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/67#issuecomment-324946774, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7Nx0y7IhjBPkkEjcJKrcSev9eJaPuvks5sbuHigaJpZM4PCR8b .

faustinoaq avatar Aug 25 '17 18:08 faustinoaq

It shows me: Failed to start the program, Timeout after 5000 milli-seconds

Estebjor avatar Aug 25 '17 18:08 Estebjor

Ok, I need more information about your environment, What is your Operative System?

On Fri, Aug 25, 2017 at 1:29 PM, Estebjor [email protected] wrote:

It show me: Failed to start the program, Timeout after 5000 milli-seconds

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/67#issuecomment-325002700, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7Nx8F9-WAjhyQY1AQmt16Pw4jEh2euks5sbxKlgaJpZM4PCR8b .

faustinoaq avatar Aug 25 '17 18:08 faustinoaq

I'm using win10.

Estebjor avatar Aug 25 '17 18:08 Estebjor

Seems you have some different configuration in your machine.

I also have Windows 10, and this extension works well: (I used your code as example)

issue67

faustinoaq avatar Aug 26 '17 02:08 faustinoaq

it is a bug that we can't use internal terminal for user input while in debug mode. for Python/C# internal terminal is working fine while debugging. I guess the issue is more on the VS code side but not sure.

GorvGoyl avatar Sep 09 '17 19:09 GorvGoyl

This was the original issue :sweat_smile:

faustinoaq avatar Sep 16 '17 04:09 faustinoaq

I don't think that this is a VS Code issue.

The only question is: does the Java debugger support to communicate over a separate communication channel so that stdin/stdout if freely available to the Java program. If the debugger itself uses stdin/stdout to communicate with the user, the Java program cannot read from stdin at the same time.

weinand avatar Sep 16 '17 09:09 weinand

I was a bit confused, My bad :sweat_smile:

faustinoaq avatar Sep 16 '17 10:09 faustinoaq

@weinand Thanks for keep discussion here :+1:

faustinoaq avatar Sep 16 '17 10:09 faustinoaq

I added this issue to Known issues in README for now.

Also I added a tiny Contributing guide if someone want to help to fix this.

faustinoaq avatar Sep 16 '17 10:09 faustinoaq