Sublime does not display the output of codes that I am certain are coded correctly, even a simple hello world program will not actually output anything.
Sublime won't display program output
Can you explain how you are trying to run the program?
What language is your program?
Can you show you code?
I’m coding in java, this is my code. It outputs nothing.
public class L1E1 {
public static void main(String[] args) {
// write your code here
for (int i = 1; i < 31; i++) {
System.out.println("hello");
if ((i%3 == 0) && (i%5 == 0)){
System.out.println(i + "FizzBuzz");
}
else if (i % 3 == 0){
System.out.println(i + "Fizz");
}
else if (i % 5 == 0){
System.out.println(i + "Buzz");
}
else {
System.out.println(i);
}
}
}
}
Based on your problem description and the fact that you’re using Java, my guess would be that you’re using the built in build system for Java, which looks like this:
{
"shell_cmd": "javac \"$file\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java"
}
This only compiles the current file, it doesn’t run it. As such you’re not seeing any output because none is being generated. On the whole Java doesn’t really lend itself to single file programs because most programs contain more than one class and every class must be in its own file.
To compile and run a java program your best bet is to use the appropriate tools to manage the build, such as Ant or Maven. There is a built in build system in Sublime that knows how to handle Ant builds, for example.
Failing that you can define your own build system for building and running a single file. Note however that once you proceed in your learning past simple one file programs, it will no longer suffice. You can create a build by using Tools > Build System > New Build System...
from the menu, altering the template, and then saving the file.
The following forum post contains an example of such a build:
It is working here:
I think you are only compiling the java code, instead of compiling and running it.
It actually works here because I had implemented a special build system for Java which is not shipped with Sublime Text:
I use shell scripts (from Cygwin) to do so. Are you on Windows? Do you have access to Cygwin?
Create these files on your Packages/Java
directory, and select the Java Single Class
build rule to run your program.
-
Packages/Java/Java Single Class.sh
javac "$1" java "$2"
-
Packages/Java/Java Single Class.sublime-build
{ "working_dir": "$file_path", "cmd": ["sh", "$packages/Java/Java Single Class.sh", "$file", "$file_base_name"], "selector": "source.java, source.jar", }
With a little change you can do that using Windows Batch files:
-
Packages/Java/Java Single Class.bat
javac "%1" java "%2"
-
Packages/Java/Java Single Class.sublime-build
{ "working_dir": "$file_path", "cmd": ["$packages/Java/Java Single Class.bat", "$file", "$file_base_name"], "selector": "source.java, source.jar", }
See also other tutorials on Google: