How to return from void function in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            f("java");
            f("c");
            f("python");

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }

    static void f(String s) {
        if (s.length() >= 6) {
            return;
        }
        System.out.println(s);
    }
}

/*
              
run:
 
java
c
     
 */

 



answered Dec 4, 2016 by avibootz

Related questions

...