Operations in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Operations in Java

I'm learning about operators in Java; I've learned about the modulo operator, which takes the remainder of division. Here's the code for the "Try it Yourself": public class Program { public static void main(String[] args) { int value = 23; int res = value % 6; System.out.println(res); } } Yet I thought, "void," meant that a method does not return a value. Is "res," which is in this case, 5, a return value?

23rd Feb 2018, 9:41 PM
Webber2190
Webber2190 - avatar
1 Answer
+ 1
Void means as you said, that the method does not return anything, and by returning anything means nothing that can be stored in a variable to be used on another algorithm. Please consider that the method in your example is the "main" method, which is the entry point of an application in java, and by default it must be declared public, static and void. It'll become clearer as you keep progressing in your learning. Good luck Webber.
23rd Feb 2018, 9:56 PM
Roberto Guisarre
Roberto Guisarre - avatar