You may choose to write your code in a standard text editor or in the contest screen. Name your class Main, the system puts it in a file named Main.java.
To write code, in the contest window, select your chosen language from the drop down menu at the top right side of the screen. Type your code into the box (ignore the Python 2 code it automatically provides).
Enter test input such as the provided sample input into the box on the mid right side of the screen. Click on the test button to compile and run your code using the test input. You will see results appear in the bottom right box.
To submit code for judging, click on the submit button. Feedback will appear in the bottom right box.
This is optional but can be done on the campus Linux system. Compile your programs on the terminal command line as follows:
This will produce a Java bytecode file named Practice.class.
To run while reading input from the prompt, run your programs on the terminal command line as follows:
input is the name of a file containing your input. The < redirects the contents of the input file into your program as if you were typing them at the prompt. It is not doing file I/O.
// Read in an unknown amount of input and prints the input followed by the sum. import java.util.Scanner; public class Practice { public static void main(String[] args) { int x; int sum = 0; Scanner s = new Scanner(System.in); while(s.hasNext()) { x = s.nextInt(); System.out.println(x); sum = sum + x; } System.out.println(sum); } }
// Read in input until you see a 0 and prints the input followed by the sum. import java.util.Scanner; public class Practice { public static void main(String[] args) { int x; int sum = 0; Scanner s = new Scanner(System.in); x = s.nextInt(); while(x != 0) { System.out.println(x); sum += x; x = s.nextInt(); } System.out.println(sum); } }