Java For Android #15: Methods - Not operation
Code:
package com.example; public class java {
public static void main(String[] str) {
boolean bool1 = not_operation(true);
System.out.println("first output " + bool1);
boolean bool2 = not_operation(false);
System.out.println("Second output " + bool2); }
public static boolean not_operation(boolean in){
boolean out = false;
if (in == true){
out = false;
}
else if (in == false){
out = true;
}
return out;
}
}
Reusing the code is a desirable trait in the programming world. Methods provide this feature as a plus. In this tutorial, I have implemented a simple program of boolean not operation. Where the output is the reverse of the input. As an argument, I have taken a boolean value and returned a boolean result from the method.
Comments
Post a Comment