Update Running_Code.mdx

This commit is contained in:
nchn27 2020-07-19 04:11:19 -04:00 committed by GitHub
parent ac7aae3b50
commit 8f3549271d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,7 @@
---
id: running-code
title: Running Code
author: Benjamin Qi, Hankai Zhang, Anthony Wang, Nathan Wang
author: Benjamin Qi, Hankai Zhang, Anthony Wang, Nathan Wang, Nathan Chen
description: Options for running your language of choice.
prerequisites:
- choosing-lang
@ -42,7 +42,7 @@ You can also share code with [pastebin](https://pastebin.com/) or [hastebin](htt
<CPPSection>
You can run from the command line and use a text editor of your choice.
You can run your C++ programs from the command line and use a text editor of your choice. Read below for different options to create and run C++ programs.
## Text Editors
@ -269,6 +269,57 @@ Now you can easily compile and run `name.cpp` from the command line with `co nam
</CPPSection>
<JavaSection>
First, download the [JDK](https://docs.oracle.com/en/java/javase/14/install/overview-jdk-installation.html#GUID-8677A77F-231A-40F7-98B9-1FD0B48C346A). Then, test that you can use the right commands.
On Windows, open `cmd` and type the following command into the prompt:
```
java
```
If you get the below result, you may have to add the JDK to your [PATH](https://docs.oracle.com/en/java/javase/14/install/installation-jdk-microsoft-windows-platforms.html#GUID-A7E27B90-A28D-4237-9383-A58B416071CA) variable.
```
'java' is not recognized as an internal or external comman,
operable program or batch file
```
If you get a list of command arguments to the `java` command, then you're probably good to go.
<IncompleteSection>
What do you have to do on Mac to get Java working the command line?
</IncompleteSection>
Running a Java file off of the command-line is relatively simple after the JDK is downloaded.
Consider this code of `Main.java` and assume it is in a file on your computer:
```java
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
```
Use the `cd` command to get to the directory that contains `Main.java`. Then, run the following command to compile the code:
```
javac Main.java
```
If it runs successfully, a file called `Main.class` will show up in the same directory, which can be executed with the next command:
```
java Main
```
If everything goes accordingly, the console should output `Hello World!`.
If you do USACO-style file I/O, meaning that files are in the "local directory", then the files must be located in the same directory as the source code (if you use the above method).
</JavaSection>
<PySection>
Download Python through [the official website](https://python.org). On Windows and Mac, you can download executable files directly; on Linux, you must either download the Python source code and compile from source, or obtain Python through your package manager.