Talk about using Java input wait (Scanner) in VS Code

Introduction

It all started when I decided to solve this with VS Code.

-A: First Attokoda (Welcome to AtCoder) --practice contest | AtCoder

Problem statement Takahashi wants to process the data. Given the integers a, b, c and the string s. Display the integer a + b + c and the string s side by side.

Run Java with VS Code (debug)

In order to execute (debug) Java with VS Code, an extension called Debugger for Java is required.

Well, the story around that is troublesome, so I'll omit it. If you google it, it will come out, so no matter what.

Normally, it starts debugging with F5, but at that time you need a configuration file called launch.json. By default, it should look like this.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch)",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopOnEntry": false,
            "mainClass": "",
            "args": ""
        }
    ]
}

However, if you execute it in this state, it will be output to the "debug console" at the bottom of VS Code. スクリーンショット (9).png

With this, you can check the output, but you cannot accept the input with Scanner like the answer example of AtCoder mentioned above.

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//Integer input
		int a = sc.nextInt();
		//Space-separated integer input
		int b = sc.nextInt();
		int c = sc.nextInt();
		//Character string input
		String s = sc.next();
		//output
		System.out.println((a+b+c) + " " + s);
	}
}

Rewrite launch.json

In conclusion, all you need to do is rewrite the " console ":" internal Console " in launch.json. If you rewrite this to " console ":" integratedTerminal " and then execute it, the output destination will change from "debug console" to "terminal" and you will be waiting for input as shown below. スクリーンショット ().png If you enter any input in the terminal in this state, it will be read into Scanner. スクリーンショット ()2.png

Summary

However, I thought that this problem, the input is given as an argument of the main function, but it is different. Japanese rubbers cashine

Recommended Posts

Talk about using Java input wait (Scanner) in VS Code
Java Spring environment in vs Code
Continued Talk about writing Java in Emacs @ 2018
Acquisition of input contents using Scanner (Java)
Try using Sourcetrail (win version) in Java code
Try using Sourcetrail (macOS version) in Java code
Using Gradle with VS Code, build Java → run
[Mac] Install Java in Visual Studio Code (VS Code)
java Scanner loop input
Differences in code when using the length system in Java
Try using RocksDB in Java
Read standard input in Java
Create QR code for Google Authenticator using ZXing in Java
Java in Visual Studio Code
Write Java8-like code in Java8
About abstract classes in java
[Note] A story about changing Java build tools with VS Code
Let me do VS Code Remote Development + Java development in Proxy environment
Avoid character code error in java when using VScode extension RUN-CODE
Guess the character code in Java
Very simple input reception in Java
Encrypt using RSA cryptography in Java
Java 15 implementation and VS Code preferences
[Java] Boilerplate code elimination using Lombok
Java build with mac vs code
HTTPS connection using tls1.2 in Java 6
I tried using JWT in Java
About file copy processing in Java
Java development environment (Mac, VS Code)
Sample code using Minio from Java
I tried to make a talk application in Java using AI "A3RT"
About the phenomenon that StackOverflowError occurs in processing using Java regular expressions
About returning a reference in a Java Getter
I tried using Elasticsearch API in Java
Prepare Java development environment with VS Code
Using Hystrix and Sentinel in code example
About Spring Dependency Injection using Java, Kotlin
Map without using an array in java
[Creating] A memorandum about coding in Java
Study Java Try using Scanner or Map
Using JavaScript from Java in Rhino 2021 version
Receive joystick input in Java LW JFL
Try using Spring Boot with VS Code
About Records preview added in Java JDK 14
Read Felica using RC-S380 (PaSoRi) in Java
Hello World on Mac VS Code Java
All same hash code string in Java
Console input in Java (understanding the mechanism)
[Mac] Install Java in Visual Studio Code
Impressions and doubts about using java for the first time in Android Studio