In Java, a void
function (or method) does not return any value. However, you can use the return
statement to exit the method early if needed. The return
statement in a void
method does not return any value, it simply exits the method.
Here’s an example:
public class Ex1 { public static void main(String[] args) { // Define items and their weights printMessage(true); printMessage(false); } public static void printMessage(boolean condition) { if (condition) { System.out.println("Condition is true!"); return; // Exits the method early if condition is true } System.out.println("Condition is false!"); } }
Condition is true! Condition is false!
Is Java Hard to Learn is it True? Java is one of the most popular…
Generating Random Numbers with Weights in Java Random number generation with weighted probabilities is a…
Introduction to JSP AJAX CRUD Applications Building web applications has become more dynamic with the…
Relationships: Hotel ↔ Rooms (One-to-Many) A hotel can have many rooms, but a room belongs…
Introduction to Grocery Inventory Apps Managing grocery inventory can be a daunting task, but with…
This article explain how to make a Fish Inventory Management App in Angular.this app explain…