Lin0523
Lin0523

Reputation: 171

Create the UNIX Echo class in Java

I am very very new to java and I'm trying to create the echo class found in UNIX in java. Basically, if I type in:

Echo 'i love you'

the command line prints

i love you

I have that part figured out, however, I can't seem to figure out the command line option -n which gets rid of the newline

I edited by code after reading the comment. However, it is still not doing what I hoped. My new code

The output of my new code As you can see, even after I enter the -n, the word is still on a newline

Upvotes: 0

Views: 171

Answers (2)

bdavies6086
bdavies6086

Reputation: 382

The solution, as seen in the comments is to use System.out.print as opposed to System.out.println

Upvotes: 1

Nikolas
Nikolas

Reputation: 44456

In Java the array starts with 0. So the code should look like this>

if (args[0].equals("-n")

By the way, you should compare two strings with string.equals(..) method, not with the double equation operator.

Upvotes: 2

Related Questions