How to return boolean from a function based on expression in Java

2 Answers

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            if (qualified_age(23))
                System.out.println("yes");
            else
                System.out.println("no");
            
            if (qualified_age(12))
                System.out.println("yes");
            else
                System.out.println("no");
            
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
    static boolean qualified_age(int age) {
	    return age >= 18 && age <= 75;
    }
}

/*
             
run:

yes
no
    
 */

 



answered Dec 1, 2016 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            System.out.println(check4("java"));
            System.out.println(check4("c"));
            System.out.println(check4("python"));

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

static boolean check4(String s) {
	return s.length() <= 4;
    }
}

/*
              
run:
 
true
true
false
     
 */

 



answered Dec 5, 2016 by avibootz

Related questions

1 answer 185 views
2 answers 237 views
1 answer 224 views
1 answer 256 views
...