Lynk Library of Knowledge

9496 Lynk's site for housing knowledge and information for the team.


Project maintained by LynkRobotics Hosted on GitHub Pages — Theme by Jimmy McCosker

Part Four





Preface


In this part you will learn about making a method We will be using this block of Java code for this part.

public class JavaIntro4 {                       
    /*add 4 to the paramter sent to the method and return the result*/
    public static double addFour(double num){   // the varible type before the method name is what type will be returned
        return num + 4;                         //return is the keyword that tells java to end the method and send the value
    }
    
    /*if the boolean named bol is true than print out the double named num*/
    public static void ifTruePrint(boolean bol, double num){    //void means the method won't return any value
        if (bol){
            System.out.println(num);
        }
    }                                                           //this method doesn't return a value
    
    public static void main(String args[]) {    //This line lets Java know what to run when you click execute below
      boolean b1 = true;                        
      boolean b2 = false;
      double x = 10;
      double y = 20;
      
      System.out.println(addFour(x));
      
      ifTruePrint(b1, x);                       //if b1 is true print x
      ifTruePrint(!b1, y);                      //if b1 is not true print y
    }                                          
}  




Previous Page / Home / Next Page




Table Of Contents