Development > Coding

Learning Java Programming on Linux

(1/4) > >>

Homework:
Hello, I'm new to Linux Lite OS and programming.
At the moment, I'm learning Java programming from a course at Udemy and I've encountered a problem with empty spaces in outputs.

Here's part of the codes:

--- Code: ---public String toString()   
{
        return first + " " + middle + " " + last;   
}

Name myName = new Name("Cookie" + "Monster" + "Jr");
System.out.println("myName: " + myName.toString());
--- End code ---

Then I compiled the codes and here's what it's shown on the Terminal:

--- Code: [email protected]:~/Documents/java$ javac NameTest.java
[email protected]:~/Documents/java$ javac Name.java
[email protected]:~/Documents/java$ java NameTest
myName:   CookieMonsterJr
--- End code ---

All the spaces are appearing right before the name. I'm using Linux's Text Editor. Could this the reason why the codes are not working properly?

bitsnpcs:
I don't know how to write Java, have you tried changing -

--- Code: ---last;}
--- End code ---
 
change to 

--- Code: ---last};
--- End code ---

Homework:
Hello bitsnpcs, thank you so much for replying to almost all my posts.
Unfortunately this error message appeared when I tried changing the position of the semicolon:

--- Code: ---Name.java:39: error: ';' expected
return first + " " + middle + " " + last
                                        ^
1 error
--- End code ---

This course is conducted using Windows OS, notepad, and CMD. Since my Windows OS crashed unexpectedly, I decided to carry on the course on Linux Lite. There are other web resources out there that recommended Vim, emacs or DrJava to learn Java on Linux platform, so I just want to confirm if this issue is really because I'm using Lite's text editor.

bitsnpcs:
Hello Homework,

Hopefully someone will answer you soon about this. :)
Linux Lite is more stable than Windows, it will be good for your course learning, once the issue is solved.

I looked at the Udemy where you learn, I liked the beginners Ethical Hacker course contents, it is not free though.

firenice03:
Giving it a quick look... The part listed...

--- Code: ---new Name("Cookie" + "Monster" + "Jr")
--- End code ---
Although you have spacing between " + there isn't any coded spaces..


Maybe try, see if it results properly

--- Code: ---new Name("Cookie " + "Monster " + "Jr")
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version