1

I have a program in Java that takes the users input of a number, converts it to a string and then reverses the number and prints it out (e.g: INPUT: 789 OUTPUT: 987).

This program runs in every other IDE except Sublime Text 3. I'm assuming this is a problem with my copy of Sublime Text but I don't have the slightest clue whats causing it as all of the code is correct. Anyone have any ideas?

Code below:

import java.util.Scanner;

public class Reverse {
public static void main(String[] args) {
    System.out.println("Enter a number: ");
    Scanner reader = new Scanner(System.in);
    int number = reader.nextInt();
    String numbs = Integer.toString(number);

    String reverse = new StringBuffer(numbs).reverse().toString();

    System.out.println(reverse);

}
}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
c.timothy
  • 97
  • 10

2 Answers2

0

You shouldnt rely too much on Sublime3 ... it is still a beta version

enter image description here

Keep using another IDE and try instead with a StringBuilder..

String reverse = new StringBuilder(numbs).reverse().toString();
System.out.println(reverse);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

I tried few online documents to configure java on subl 3, beta relase from subl3 had only Javac, installed javatar plugin to run java.

  1. javatar is a Java plugin available for subl, you can install it from install packages menu

  2. create build javatar, it will create a file javatar.sublime-build

  3. edit the javatar.sublime-settings

javatar.sublime-build

{
    "cmd": ["javac \"$file_name\" && java \"$file_base_name\""],
    "shell": true,
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
    "selector": "source.java"
}

javatar.sublime-settings

{
    "java_executables":
    {
        "build": "javac",
        "lint": "javac",
        "run": "java",
        "script": "jrunscript",
        "version": "java"
    },
    "java_runtime_files":
    {
        "runtime":
        [
            "rt.jar"
        ]
    },
    "jdk_installation":
    {
        "linux":
        [
            "/opt/jdk/jdk1.8.0_60/bin/"
        ]
    },
    "project_data":
    {
        "2": null
    }
}

Please note: it works for static code, not suitable for interactive where we need to get some input from user using Scanner.

Saravana
  • 12,647
  • 2
  • 39
  • 57