0 Members and 2 Guests are viewing this topic.
Name myName = new Name("Cookie" + "Monster" + "Jr");
Name myName = new Name("Cookie", "Monster", "Jr");
I have no idea if that is the problem, but the text editor I use (Leafpad) has an option to set the required line terminator to CRLF or just LF. I can only suggest trying it as I do not use Java.
Hello, I use the gedit and terminal for the Python book I use, I had a look on Google it says gedit can be used for Java with the terminal.I think they call it ethical because it is legal like pentesting.
Quote from: justme2 on July 24, 2017, 03:53:06 PMI'm not familiar with java either, but one thing springs to mind - I think windows and linux use different line terminators in text editors, CRLF and LF. Could that be the problem?Hello justme2, thank you for pointing out the difference!So I found this article: https://blog.codinghorror.com/the-great-newline-schism/, unfortunately I'm still none the wiser on how this would affect Lite text editor processing the empty spaces.Windows text editor save encoding as ANSI, while Lite text editor save encoding as UTF-8. Could this be the reason for this problem?
I'm not familiar with java either, but one thing springs to mind - I think windows and linux use different line terminators in text editors, CRLF and LF. Could that be the problem?
Giving it a quick look... The part listed... Code: [Select]new Name("Cookie" + "Monster" + "Jr")Although you have spacing between " + there isn't any coded spaces.. Maybe try, see if it results properlyCode: [Select]new Name("Cookie " + "Monster " + "Jr")
new Name("Cookie" + "Monster" + "Jr")
new Name("Cookie " + "Monster " + "Jr")
public class Name{ private String first; private String middle; private String last; // constructor methods allow us to declare class objects and provide those objects with some data. public Name(String f, String m, String l) { first = f; middle = m; last = l; } public Name(String f, String l) { first = f; middle = ""; last = l; } public Name(String l) { first = ""; middle = ""; last = l; } //default constructor - it's a good idea to add one that doesn't have data in them public Name() { first = ""; middle = ""; last = ""; } public String toString() { return first + " " + middle + " " + last; }}
public class NameTest{ public static void main(String[] args) { // instantiation - creating an instance of the Name class Name myName = new Name("Cookie" + "Monster" + "Jr"); Name yourName = new Name("Great" + "Cookie"); Name aName = new Name("Durr"); System.out.println("myName: " + myName.toString()); System.out.println("yourName: " + yourName.toString()); }}
I looked at the Udemy where you learn, I liked the beginners Ethical Hacker course contents, it is not free though.
Name.java:39: error: ';' expected return first + " " + middle + " " + last ^1 error