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.
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.
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);
}
}
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.
If you enter any input in the terminal in this state, it will be read into Scanner
.
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