Hey guys, I'm trying to create my own personal API (more like a simple way for me to write long codes), and i've run into a snag. I want to create a simple function to detect whether or not I want the consoleWrite() to print out a new line system out, or to keep it on the same line.
I.E: When the users prompts to exit the terminal, it comes up with a

Are you sure you want to exit? (Y/N)

and I want it to stay on the same line, so the Y or N comes right after the output.
I have some kind of idea on how to do this, like, in the function to prompt for the same line, it could be something like this..

consoleWrite("Hello World!", "null");

But how do I make my API program detect if the code contains the "null" part or not and then print out the correct system out? I know this will include an "if" statement, but that's as far as I know. Any help on this will be perfect!

detect if the code contains the "null" part

The String class has methods for comparing the contents of a String.
The consoleWrite() method could use an if statement with a String method to see if its second argument is the String: "null"

Close this thread. I worked it out by creating an overloaded constructor with 2 strings for the same line system out.

But if there is someone out there with a more productive way of doing this, I'm open to suggestions!

The simplest solution would be to introduce a new "command" like consoleWriteLn (similar to print v/s println when using System.out). So if the user uses "consoleWrite" it would correspond to System.out.print whereas if the user uses consoleWriteLn .

BTW, why not use shorter commands like print and println ?

This article has been dead for over six months. Start a new discussion instead.