So I don't know much about java but I noticed this worked then according to my class notes I should be doing it a different way
Here's what my notes have
System.out.print("hello");
System.out.print(name);
System.out.print("\n");
However I tried this and it also does the same thing. It's shorter so is this an acceptable way to do it or will it break down the road?
System.out.print("hello"+name+"\n);
Also as long as the code runs right my teacher shouldn't care right? It's my first class and I'm not a computer science major.
System.out.println("hello"+name);
)as long as the code runs right my teacher shouldn't care right?
- this is rarely the case. In this situation, what you have is fine; however, there are many cases where how you code something is equally important as how well it runs.Strings
while on the second attempt, you are putting together 3Strings
into one and printing it once - same result. Less code to write, and read/maintain ;)