Sublime Forum

Output wont show after user input manipulated

#1

Hi I’m having a problem with sublime text 3.
Some code I’ve written that takes the users input of a number, converts it to a string then reverses it and prints it out wont show the reversed string.
The code is fine as it runs without error in other IDE’s but Sublime wont for some reason.
The code does make use of the scanner utility and string buffers but I can’t see how either of those would cause the problem.
I’ve added the code bellow if anyone wants to try it out on theirs to see if its maybe just a bad install I have.

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);

}
}
0 Likes

How to end and accept an input() command?
#2

When external programs are run from within Sublime there’s no way to send input from the console to the standard input of whatever you ran.

As a result, your code is hanging in I/O wait for data to appear on stdin but that’s never going to happen. If you add a println after reader.nextInt() to log the number entered by the user, you’ll see that no matter what you enter, it never triggers.

2 Likes

#3

So there’s no way to use anything like java.util.scanner inside sublime text?

0 Likes

#4

https://packagecontrol.io/packages/SublimeREPL

0 Likes