0

Difference between giving a value to the output screen by using return and using System.out.println()?

17th Jan 2017, 3:32 PM
Kolla Saikumar
Kolla Saikumar - avatar
1 Answer
+ 2
The differences between the two can be subtle at first. Return is used when a return type is specified for the function, such as int, string, etc. Looks like this: public int function() { return x } Because I specified what type the function should return it must have a return at the end and it must give the specified type (int in this case). The big thing is that after return is called the program stops processing the code, this is why it is always at the end. Now System.out.println() can be used anywhere at anytime within your program and has fewer restrictions as to what it can print out. Generally you just need to make sure that whatever is input is of the same data type. This means you'll have to convert one if you want to say print a string and an integer together in one print statement. Hope this helps
17th Jan 2017, 3:58 PM
Sean Kudebeh
Sean Kudebeh - avatar