From 8f3549271da3a51ab53e1c5c637b3c287d23d645 Mon Sep 17 00:00:00 2001 From: nchn27 <46332369+nchn27@users.noreply.github.com> Date: Sun, 19 Jul 2020 04:11:19 -0400 Subject: [PATCH] Update Running_Code.mdx --- content/1_Intro/Running_Code.mdx | 55 ++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/content/1_Intro/Running_Code.mdx b/content/1_Intro/Running_Code.mdx index 066df93..f696a27 100644 --- a/content/1_Intro/Running_Code.mdx +++ b/content/1_Intro/Running_Code.mdx @@ -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 -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 + + +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. + + + +What do you have to do on Mac to get Java working the command line? + + + +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). + + + 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.